Skip to content

Commit a12cf66

Browse files
authored
Merge pull request #4682 from KoenZomers/Get-PnPFileCheckedOut
Added `Get-PnPFileCheckedOut`
2 parents 8cd6641 + 8ce82b1 commit a12cf66

File tree

6 files changed

+183
-1
lines changed

6 files changed

+183
-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 [#4682](https://github.com/pnp/powershell/pull/4682)
5354
- Added `Get-PnPTenantPronounsSetting` and `Set-PnPTenantPronounsSetting` cmdlets to manage the availability of using pronouns in the organization [#4660](https://github.com/pnp/powershell/pull/4660)
5455
- Added `HidePeopleWhoHaveListsOpen` parameter to `Set-PnPSite` cmdlet to hide people who simultaneously have lists open [#4699](https://github.com/pnp/powershell/pull/4699)
5556

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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+
Notice: if this cmdlet would return more then 5,000 results, so 5,000 or more checked out files, it will not work and will throw an error. This is unfortunately a limitation of SharePoint Online and not something that can be fixed in the cmdlet. As long as the number of checked out files is below 5,000, this cmdlet will work as expected, even on document libraries that contain more than 5,000 files.
26+
27+
## EXAMPLES
28+
29+
### EXAMPLE 1
30+
```powershell
31+
Get-PnPFileCheckedOut -List "Documents"
32+
```
33+
34+
Returns all files that are currently checked out in the "Documents" library.
35+
36+
## PARAMETERS
37+
38+
### -Connection
39+
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.
40+
41+
```yaml
42+
Type: PnPConnection
43+
Parameter Sets: (All)
44+
45+
Required: False
46+
Position: Named
47+
Default value: None
48+
Accept pipeline input: False
49+
Accept wildcard characters: False
50+
```
51+
52+
### -List
53+
The list instance, list display name, list url or list id to query for checked out files
54+
55+
```yaml
56+
Type: String
57+
Parameter Sets: (All)
58+
59+
Required: True
60+
Position: 0
61+
Default value: None
62+
Accept pipeline input: True (ByValue)
63+
Accept wildcard characters: False
64+
```
65+
66+
## RELATED LINKS
67+
68+
[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>CheckedOutBy.Email</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)