PowerShell Script to Cleanup all Recycle Bins in a Site Collection in SharePoint 2013

  • Open PowerShell window in your system.
  • Paste the below code in your PowerShell window.
  • Run the script.
  1. [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint");  
  2. $url = $args[0];  
  3. $site = new-object microsoft.sharepoint.spsite($url);  
  4. for ($i=0;$i -lt $site.allwebs.count;$i++)  
  5. {  
  6.   write-host $site.allwebs[$i].url "...deleting" $site.allwebs[$i].recyclebin.count "item(s).";  
  7.   $site.allwebs[$i].recyclebin.deleteall();  
  8. }  
  9. write-host $site.url "...deleting" $site.recyclebin.count "item(s).";  
  10. $site.recyclebin.deleteall();  
  11. $site.dispose(); 
Ebook Download
View all
Learn
View all