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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
#Author: Alexey Beliaeff #URL: http://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 |