OK, so following my post from September 8th, 2021: [SPO] Delete document library folder contents using PNP PowerShell
I got asked what can we do if we have a list/library that is over the normal list-view threshold.
Well, here’s a script that can help:
1 2 3 4 5 6 7 8 9 10 11 |
#Config Variables $SiteURL = "https://test.sharepoint.com/sites/test" $ListName ="LIBTESTMULTI" #Connect to PNP Online Connect-PnPOnline -Url $SiteURL -Interactive Get-PnPList -Identity $ListName | Get-PnPListItem -PageSize 100 -ScriptBlock { Param($items) Invoke-PnPQuery } | ForEach-Object {$_.Recycle() } |
As you can see, the script works in “bathes” of items then moves the items to the recycle bin.
So, here’s a way to remove the items from the recycle bin:
1 2 3 4 5 6 7 8 9 10 11 |
#Config Variables $SiteURL = "https://test.sharepoint.com/sites/test" #Connect to Tenant Admin Site Connect-PnPOnline -Url $SiteURL -Interactive #Get recycle bin items in batches and delete them permanently While( (Get-PnPRecycleBinItem -RowLimit 500) -ne $null) { Get-PnPRecycleBinItem -RowLimit 500 | Clear-PnPRecycleBinItem -Force } |
If you monitor the recycle bin items in the site contents, you will see the number decrease:
Until it reaches 0 (zero):
Hint: if you want to bulk generate a large number of items and then upload them to SharePoint, you can use:
1 |
1..100 | foreach {new-item -path C:\testdata\Testdata$_.txt} |
Enjoy!