pnp / PnP-PowerShell

SharePoint PnP PowerShell CmdLets
https://pnp.github.io/powershell
Other
987 stars 665 forks source link

Get-PNPRecycleBinItem and Restore-PNPRecycleBinItem fail with "User not found" error #2259

Open westleyMS opened 4 years ago

westleyMS commented 4 years ago

Reporting an Issue

When using Get-PNPRecycleBinItem more than once in a function, sometimes we get a "User not found" error response from the server. When looking at the ULS, the call fails when it is trying to fetch the author property. We are not trying to fetch the Author property, the PNP is fetching this. Once we converted the calls to use CSOM directly, this issue stops occurring. This also seems to only happen when processing a large number of items. This also happens sometimes when calling Restore-PNPRecycleBinItem.

The code we are using cycles thru URLs to OD4B sites (one drive personal sites) and feeds each one into the Connect-PNPOnline call. Then the code loops through this-

Connect-PNPOnline -url https://-my.sharepoint.com -Credentials get-credentials Write-Host $path

Get-PnPRecycleBinItem | ? DeletedByName -eq 'System Account' | Export-Csv $path
try
{
   Get-PnPRecycleBinItem -FirstStage | ? DeletedByName -eq ‘System Account’ | Restore-PnPRecycleBinItem -Force
   Get-PnPRecycleBinItem | ? DeletedByName -eq 'System Account' | Export-Csv $notrestored
}
catch
{ Write-Host $_.Message }

Expected behavior

The commands should succeed to fetch or restore as indicate by the command name.

Actual behavior

Error is returned- "User cannot be found"

Steps to reproduce behavior

  1. Create 200 test documents in the default library
  2. Delete test documents created in step 1
  3. Make sure they are in the recycle bin
  4. Use code like this- Connect-PNPOnline -url https://-my.sharepoint.com -Credentials get-credentials Write-Host $path

    Get-PnPRecycleBinItem | ? DeletedByName -eq 'System Account' | Export-Csv $path try { Get-PnPRecycleBinItem -FirstStage | ? DeletedByName -eq ‘System Account’ | Restore-PnPRecycleBinItem -Force Get-PnPRecycleBinItem | ? DeletedByName -eq 'System Account' | Export-Csv $notrestored } catch { Write-Host $_.Message }

Which version of the PnP-PowerShell Cmdlets are you using?

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

3.13.1909.0

How did you install the PnP-PowerShell Cmdlets?

I believe this issue is caused by line 49 of this file: https://github.com/SharePoint/PnP-PowerShell/blob/master/Commands/RecycleBin/GetRecycleBinItem.cs

I believe the 'RetrievalExpressions' might need to be 'DefaultRetrievalExpressions' as this is defined on line 44 and never used. Somehow it is trying to get the author and that seems to gum up the call, even when we are not trying to retrieve that property.

ghost commented 4 years ago

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

malabrito commented 4 years ago

I faced the same issue when trying to restore a sharepoint site collection recycle bin item by ID.