Monday, February 1, 2021

Powershell script for cleaning Recycle bin

In this blog post we will learn, how we can clean the recycle bin with PowerShell script. This is another way of cleaning Recycle bin apart from UI.

Note: Before going through the please go through my first post in power shell series which convers how to use PS scripts.

We will use the below script to clean up the items from the recycle bin.


$webApp=get-SPWebApplication "http://sharepointblog"
foreach ($SPSite in $webApp.Sites) {     #Here we are looping through all the web under site collection     foreach($SPWeb in $SPSite.AllWebs)     {         #Cleaning the 1st Stage of Recycle bin items        $SPWeb.RecycleBin.DeleteAll();         #Moving the all the items to 2nd stage level         $SPWeb.RecycleBin.MoveAllToSecondStage();     }     #Clean SharePoint site collection     $SPSite.RecycleBin.DeleteAll(); }