Skip to content

Commit 3a92e92

Browse files
committed
Implementation of Get-PnpFileCheckedOut
1 parent 8fccd8a commit 3a92e92

File tree

6 files changed

+181
-1
lines changed

6 files changed

+181
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
5050
- Added `Get-PnPFileRetentionLabel` cmdlet to fetch the file retention labels. [#4603](https://github.com/pnp/powershell/pull/4603)
5151
- Added `Get/Set/Remove-PnPUserProfilePhoto` cmdlets to download, upload or remove the profile photo of the specified user.
5252
- Added `New/Get/Remove/Update-PnPTodoList` cmdlets to manage Todo lists.
53+
- Added `Get-PnPFileCheckedOut` cmdlet to retrieve all files that are currently checked out in a library
5354

5455
### Changed
5556

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
---
2+
Module Name: PnP.PowerShell
3+
title: Get-PnPFileCheckedOut
4+
schema: 2.0.0
5+
applicable: SharePoint Online
6+
external help file: PnP.PowerShell.dll-Help.xml
7+
online version: https://pnp.github.io/powershell/cmdlets/Get-PnPFileCheckedOut.html
8+
---
9+
10+
# Get-PnPFileCheckedOut
11+
12+
## SYNOPSIS
13+
Returns all files that are currently checked out in a library
14+
15+
## SYNTAX
16+
17+
```powershell
18+
Get-PnPFileCheckedOut -List <ListPipeBind> [-Connection <PnPConnection>]
19+
```
20+
21+
## DESCRIPTION
22+
23+
This cmdlet allows to retrieve all files that are currently checked out in a library.
24+
25+
## EXAMPLES
26+
27+
### EXAMPLE 1
28+
```powershell
29+
Get-PnPFileCheckedOut -List "Documents"
30+
```
31+
32+
Returns all files that are currently checked out in the "Documents" library.
33+
34+
## PARAMETERS
35+
36+
### -Connection
37+
Optional connection to be used by the cmdlet. Retrieve the value for this parameter by either specifying -ReturnConnection on Connect-PnPOnline or by executing Get-PnPConnection.
38+
39+
```yaml
40+
Type: PnPConnection
41+
Parameter Sets: (All)
42+
43+
Required: False
44+
Position: Named
45+
Default value: None
46+
Accept pipeline input: False
47+
Accept wildcard characters: False
48+
```
49+
50+
### -List
51+
The list instance, list display name, list url or list id to query for checked out files
52+
53+
```yaml
54+
Type: String
55+
Parameter Sets: (All)
56+
57+
Required: True
58+
Position: 0
59+
Default value: None
60+
Accept pipeline input: True (ByValue)
61+
Accept wildcard characters: False
62+
```
63+
64+
## RELATED LINKS
65+
66+
[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp)

resources/PnP.PowerShell.Format.ps1xml

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3127,6 +3127,36 @@
31273127
</TableRowEntry>
31283128
</TableRowEntries>
31293129
</TableControl>
3130-
</View>
3130+
</View>
3131+
<View>
3132+
<Name>CheckedOutFile</Name>
3133+
<ViewSelectedBy>
3134+
<TypeName>PnP.PowerShell.Commands.Model.SharePoint.CheckedOutFile</TypeName>
3135+
</ViewSelectedBy>
3136+
<TableControl>
3137+
<TableHeaders>
3138+
<TableColumnHeader>
3139+
<Label>ServerRelativeUrl</Label>
3140+
<Alignment>left</Alignment>
3141+
</TableColumnHeader>
3142+
<TableColumnHeader>
3143+
<Label>CheckedOutByEmail</Label>
3144+
<Alignment>left</Alignment>
3145+
</TableColumnHeader>
3146+
</TableHeaders>
3147+
<TableRowEntries>
3148+
<TableRowEntry>
3149+
<TableColumnItems>
3150+
<TableColumnItem>
3151+
<PropertyName>ServerRelativeUrl</PropertyName>
3152+
</TableColumnItem>
3153+
<TableColumnItem>
3154+
<ScriptBlock>$_.CheckedOutBy.Email</ScriptBlock>
3155+
</TableColumnItem>
3156+
</TableColumnItems>
3157+
</TableRowEntry>
3158+
</TableRowEntries>
3159+
</TableControl>
3160+
</View>
31313161
</ViewDefinitions>
31323162
</Configuration>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using System.Management.Automation;
4+
using Microsoft.SharePoint.Client;
5+
using PnP.PowerShell.Commands.Base.PipeBinds;
6+
7+
namespace PnP.PowerShell.Commands.Files
8+
{
9+
[Cmdlet(VerbsCommon.Get, "PnPFileCheckedOut")]
10+
[OutputType(typeof(IEnumerable<Model.SharePoint.CheckedOutFile>))]
11+
public class GetFileCheckedOut : PnPWebCmdlet
12+
{
13+
[Parameter(Mandatory = true, Position = 0, ValueFromPipeline = true)]
14+
public ListPipeBind List;
15+
16+
protected override void ExecuteCmdlet()
17+
{
18+
var list = List.GetList(CurrentWeb);
19+
var checkedOutFiles = list.GetCheckedOutFiles();
20+
21+
ClientContext.Load(checkedOutFiles, cof => cof.Include(c => c.CheckedOutBy, c => c.ServerRelativePath));
22+
ClientContext.ExecuteQueryRetry();
23+
24+
checkedOutFiles.Select(c => new Model.SharePoint.CheckedOutFile
25+
{
26+
ServerRelativeUrl = c.ServerRelativePath.DecodedUrl,
27+
CheckedOutBy = new Model.User
28+
{
29+
DisplayName = c.CheckedOutBy.Title,
30+
Email = c.CheckedOutBy.Email,
31+
Id = c.CheckedOutBy.Id,
32+
LoginName = c.CheckedOutBy.LoginName
33+
}
34+
}).ToList().ForEach(WriteObject);
35+
}
36+
}
37+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
namespace PnP.PowerShell.Commands.Model.SharePoint
2+
{
3+
/// <summary>
4+
/// Contains the properties of a checked out file
5+
/// </summary>
6+
public class CheckedOutFile
7+
{
8+
/// <summary>
9+
/// Server relative url to the checked out
10+
/// </summary>
11+
public string ServerRelativeUrl { get; set; }
12+
13+
/// <summary>
14+
/// The user who has the file checked out
15+
/// </summary>
16+
public User CheckedOutBy { get; set; }
17+
}
18+
}

src/Commands/Model/User.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
namespace PnP.PowerShell.Commands.Model
2+
{
3+
/// <summary>
4+
/// Contains information about a user
5+
/// </summary>
6+
public class User
7+
{
8+
/// <summary>
9+
/// Unique identifier of the user in the user information list of the site collection
10+
/// </summary>
11+
public int? Id { get; set; }
12+
13+
/// <summary>
14+
/// Display name of the user (a.k.a. Title)
15+
/// </summary>
16+
public string DisplayName { get; set; }
17+
18+
/// <summary>
19+
/// The login name of the user
20+
/// </summary>
21+
public string LoginName { get; set; }
22+
23+
/// <summary>
24+
/// The email address of the user
25+
/// </summary>
26+
public string Email { get; set; }
27+
}
28+
}

0 commit comments

Comments
 (0)