Forum Discussion
Jussi Palo
Feb 15, 2017Iron Contributor
Office PnP PowerShell: Get file CheckOutStatus
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...
Jussi Palo
Iron Contributor
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
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() }
- Dennis GaidaJul 12, 2017Iron Contributor
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?