powershell icon indicating copy to clipboard operation
powershell copied to clipboard

[BUG] Set-PnPListItem doesnt work with batching "Cannot find item with Identity PnP.PowerShell.Commands.Base.PipeBinds.ListItemPipeBind"

Open Smevs opened this issue 2 years ago • 1 comments

When using the -batch parameter with Set-PnPListItem, it fails with the following error:

"Cannot find item with Identity PnP.PowerShell.Commands.Base.PipeBinds.ListItemPipeBind"

For example, this works (no batching):

$targetFolder = "Path/To/Folder" ForEach ($folder in $folders) { $folderUpload = Add-PnPFolder -Name $folder.FileLeafRef -Folder $targetFolder -Connection $DestinationConnection $metaData = @{ "Created" = $folder.Created_x0020_Date } # Set Metadata on folder just created Set-PnPListItem -List $DestinationLibrary -Identity $folderUpload.ListItemAllFields -Values $metaData -Connection $DestinationConnection }

Whereas, this does not, just gives error:

$targetFolder = "Path/To/Folder" $batch = New-PnPBatch -Connection $DestinationConnection ForEach ($folder in $folders) { $folderUpload = Add-PnPFolder -Name $folder.FileLeafRef -Folder $targetFolder -Connection $DestinationConnection $metaData = @{ "Created" = $folder.Created_x0020_Date } # Set Metadata on folder just created Set-PnPListItem -List $DestinationLibrary -Identity $folderUpload.ListItemAllFields -Values $metaData -Batch $batch -Connection $DestinationConnection } Invoke-PnPBatch -Batch $batch -Connection $DestinationConnection

I believe this has been the case since batching was introduced, and i have personally experienced it in versions 1.9, 1.11, 1.12 (With PS 5.1), 2.0, and now 2.2 (with PS 7.3.5)

Expected behavior

Items to be batched as per documentation to reduce API calls

Actual behavior

Each time Set-PnPListItem is called, it gives this error:

Set-PnPListItem -List $DestinationLibrary -Identity $folderUp … | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | Cannot find item with Identity PnP.PowerShell.Commands.Base.PipeBinds.ListItemPipeBind Set-PnPListItem:

Steps to reproduce behavior

See code above

What is the version of the Cmdlet module you are running?

2.2 but also experienced in older versions as mentioned above

Which operating system/environment are you running PnP PowerShell on?

  • [x] Windows
  • [ ] Linux
  • [ ] MacOS
  • [ ] Azure Cloud Shell
  • [ ] Azure Functions
  • [ ] Other : please specify

This issue has been raised a few times previously, see issues 2184, 2191 and partially related 1863. But it has been closed/unanswered each time with no resolution.

Thanks for your time.

Smevs avatar Aug 09 '23 10:08 Smevs

Additionally, if you use the item ID along with batching it does work, however, Add-PnPFolder does not return the ID so that complicates the process somewhat. The documentation says that -Identity parameter can accept either ID or the listitem object itself - both work without batching but only ID works when batching is implemented.

Smevs avatar Aug 09 '23 10:08 Smevs