Feb 15 2017 08:37 AM - edited Feb 15 2017 08:49 AM
How to check for publishing page's CheckOutStatus?
# Get pages foreach($page in Get-PnPListItem -Web $subweb -List "pages" -Fields "FileRef" | Where { $_.FieldValues.FSObjType -eq 0}) { Write-Host "Page '$($page["FileRef"])'" $file = Get-PnPFile -Url $page["FileRef"] -Web $subweb $file.CheckOutStatus #NONONO!
Feb 15 2017 10:15 PM
Check the below sample to get the file checkout status using PnP.
$DocLibName = "Documents" $Context =Get-PnPContext $List=Get-PnPList -Identity "Documents" $Allfiles= $List.RootFolder.Files $Context.Load($Allfiles) $Context.ExecuteQuery() foreach( $file in $Allfiles) { Write-Host "FileName" $file.Name "Status" $file.Level }
Feb 15 2017 11:10 PM - edited Feb 15 2017 11:28 PM
Feb 15 2017 11:10 PM - edited Feb 15 2017 11:28 PM
Thanks, looks like it cannot really be done with PnP.
How come the -Web parameter isn't working when looping subsites, it is compaining about wrong context:
foreach($subweb in Get-PnPSubWebs -Recurse) { Write-Host "Subweb '$($subweb.Title)'" $context = Get-PnPContext $list = Get-PnPList -Identity "pages" -Web $subweb # <<< Here I need to get hold of current subweb pages $allfiles = $list.RootFolder.Files $context.Load($allfiles) $context.ExecuteQuery() foreach($file in $allfiles) { Write-Host "Page '$($file.ServerRelativeUrl)'" write-host $file.Level } }
Feb 16 2017 01:47 AM
Please try the below modified script.
$cred=Get-Credential Connect-PnPOnline -Url https://itrmxxxx.sharepoint.com/sites/contosobeta -Credentials $cred $subwebs=Get-PnPSubWebs -Recurse foreach($subweb in $subwebs) { Write-Host "Subweb '$($subweb.Title)'" Connect-PnPOnline -Url $subweb.Url -Credentials $cred $context = Get-PnPContext $list = Get-PnPList -Identity "Documents" $allfiles = $list.RootFolder.Files $context.Load($allfiles) $context.ExecuteQuery() foreach($file in $allfiles) { Write-Host "Page '$($file.ServerRelativeUrl)'" write-host $file.Level } $Context.Dispose() $context.ExecuteQuery() }
Jul 12 2017 06:22 AM
Using $context.Load and ExecuteQuery does the trick $file.Level is loaded. However if using Get-PnPFile or Get-PnPListItem the Level attribute seems to not be loaded.
I didn't find a way to include more fields besides using the full execute query. Maybe a bug / feature request?
Mar 28 2018 08:50 AM
I have managed to get the checked out status of a file this way :
$lists = Get-PnPList foreach ($list in $lists | where {$_.Title -eq "Site Pages" -or $_.Title -eq "Documents"}) { $Items = Get-PnPListItem -List $list foreach ($Item in $Items) { if ($Item.FieldValues.CheckoutUser -ne $null) { write-host $list.Title -ForegroundColor Green write-host ($Item.FieldValues).FileLeafRef -ForegroundColor Yellow write-host $Item.FieldValues.CheckoutUser.Email -ForegroundColor Red } } }
If the item is checked out (in either "Site Pages" or "Documents", in this example), this script will show you the filename, and the email of the person who has it checked out.