CloudOffice365

[Solved] how to resolve error message “Exception calling “ExecuteQuery” with “0” argument(s): “The attempted operation is prohibited because it exceeds the list view threshold enforced by the administrator.””

When dealing with SharePoint files restore from recycle bin using PowerShell or Rest APl, it’s important to note that there is a limit of 5000 items for a single query or operation. This means that if you need to restore SharePoint files and the list has more than 5000 items, you’ll need to use a workaround to retrieve all the items and perform the restore.

Below is the message that you may while trying to restore using Powershell

“Exception calling “ExecuteQuery” with “0” argument(s): “The attempted operation is prohibited because it exceeds the list view threshold enforced by the administrator.”

Here’s a general outline of the steps you can take to restore SharePoint files using PowerShell when you hit the list 5000 items limit:

The following PowerShell script can be utilized to recover numerous files from the SharePoint recycle bin. However, it should be noted that files over 5K may result in an error message stating, “The attempted operation is prohibited because it exceeds the list view threshold.”

# This is the variable for the site 
$AdminURL = "https://domain.sharepoint.com/sites/Team"

# This will connect to you to the site, make sure you are a site admin for the site 
connect-PnPOnline -Url $AdminURL -UseWebLogin
Get-PnPRecycleBinItem -RowLimit 500000 | where {$_.DeletedByEmail -eq "user@domain.com"} | Restore-PnPRecycleBinItem -Force

You can run the following command to get the count of the files by a user in the recycle bin

(Get-PnPRecycleBinItem | where {$_.DeletedByEmail -eq "user@domain.com"}).count

I ran into this issue and could not restore and here are alternative steps I performed to get the restore going.

$restore = Get-PnPRecycleBinItem -RowLimit 5000 | where {$_.DeletedByEmail -eq "user@domain.com"}
$restore.count
$restore[0]
$restore[0].id
Restore-PnPRecycleBinItem -Identity 4c19b582-aaaa-46b3-fr54-77c64274bb50
Invoke-PnPSPRestMethod -Method Post -Url "/_api/site/recyclebin/restorebyids" -Content @{ids=@("4c19b582-aaaa-46b3-fr54-77c64274bb50")}
foreach ($item in $restore.id){Invoke-PnPSPRestMethod -Method Post -Url "/_api/site/recyclebin/restorebyids" -Content @{ids=@($item)}}

Running these commands did the trick and I was able to restore all the items from the recycle bin successfully.

 

 

 

 

 

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button