PnP-PowerShell icon indicating copy to clipboard operation
PnP-PowerShell copied to clipboard

Unable to retrieve Item Id using Get-PnPFolderItem

Open rjn71 opened this issue 7 years ago • 1 comments

Hi

I'm using Get-PnPFolderItem to recursively get all files and folders inside a document library in SharePoint online.

$items = Get-PnPFolderItem -FolderSiteRelativeUrl $folderurl foreach ($item in $items) { Write-Host $item.Id #doesn't work Write-Host $item.ListItemAllFields.Id #doesn't work
}

I'm unable to get Id of the item within the foreach loop unless I load the ListItemAllFields explicitly as below for each item

$items = Get-PnPFolderItem -FolderSiteRelativeUrl $folderurl foreach ($item in $items) { $item.Context.Load($item.ListItemAllFields) $item.Context.ExecuteQuery() Write-Host $item.ListItemAllFields.Id #works }

Is this the right approach? ExecuteQuery is inside foreach loop for each item just to get Id. I've got thousands of items inside the document library and looping this way takes lot of time. I need the Id as I call Set-PnPListItem for updating some metadata values. Is there a better way to do a batch update as all files inside a folder share the same metadata? I've tried piping the results of Get-PnPFolderItem to Set-PnPListItem but that doesn't work. Get-PnPFolderItem -FolderSiteRelativeUrl $folderurl | Set-PnPListItem -Values $values

Thanks

rjn71 avatar May 01 '19 16:05 rjn71

Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.

ghost avatar May 01 '19 16:05 ghost