Remove Items from SharePoint Recycle filtered by URL
If you removed a number of SharePoint list items (moved to Recycle Bin), I think you want to clean the Recycle from them. Of course you can remove them manually but it’s not a good idea if you have deleted 10000 records or more (Remove a lot of elements from very large SharePoint Lists).
The script below will help you to clean SharePoint Recycle from deleted items. The script is a bit raw but I think it’s not a problem to make it better. My result was enough for me.
#Author: Alexey Beliaeff #URL: https://markimarta.com If ((Get-PSSnapIn -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null ) { Add-PSSnapIn -Name Microsoft.SharePoint.PowerShell } $host.Runspace.ThreadOptions = "ReuseThread" function RemoveItemsFromSPRecycleBin { param ($sSiteCollection,$sOperationType,$sUser) try { $spSite=Get-SPSite -Identity $sSiteCollection $SPRecycleBinItemCollection = $spSite.RecycleBin; #$spSite.RecycleBin | Where {$_.DirName -match "site_url_mask" } | sort DirName | select Title, ItemType, DirName, ItemState $vars = $SPRecycleBinItemCollection | Where {$_.DirName -match "site_url_mask" } $nowtime = Get-Date Write-Host $nowtime Write-Host $vars.Count for($i = $vars.Count-1; $i -ge 0; $i--) { $vars[$i].Id $vars[$i].Delete() } $nowtime = Get-Date Write-Host $nowtime $spSite.Dispose() } catch [System.Exception] { write-host -f red $_.Exception.ToString() } } Start-SPAssignment –Global #Calling the function $sSiteCollection="https://spdev" RemoveItemsFromSPRecycleBin -sSiteCollection $sSiteCollection Stop-SPAssignment –Global #Remove-PSSnapin Microsoft.SharePoint.PowerShell