Friday, 4 January 2013

Empty RecycleBin in SharePoint 2010


There are total 2 Recycle bins in every site collection in SharePoint. First Recycle Bin can be called as end user recycle bin which is available in every site & sub-site of a particular site collection. This Recycle Bin is accessible through Site Actions-> View All Site Content. Whenever the user deletes the document, it is stored in this Recycle Bin.

Now, when the document from first Recycle Bin is deleted it gets stored in the Second Recycle Bin which can also be called as Admin Recycle Bin. This is available only at site collection level. This Recycle Bin is accessible through Site Actions-> Site Settings-> Site Collection Administration.

$WebApp=get-spwebapplication "http://sharepoint-site-name"

    foreach ($SPSite in $webApp.Sites)
    {
         #get the collection of webs
      foreach($SPWeb in $SPSite.AllWebs)
         {
             #Empty the 1st Stage Recycle bin items PERMENANTLY which is available in All Site Content
             #$SPWeb.RecycleBin.DeleteAll();
             
             #Send the 1st Stage Recycle bin items to 2nd Stage
             $SPWeb.RecycleBin.MoveAllToSecondStage();

              write-host "End-User Recycle Bin Items Deleted for:"
              write-host $SPWeb.title ":" $SPWeb.URL "`n"
         }
             #Empty SharePoint site collection recycle bin (2nd Stage Recycle bin) or Admin Recycle bin which is available in the Site Settings page of root site collection
             $SPSite.RecycleBin.DeleteAll();

  write-host "Administrator Recycle bin Items Deleted for:" $SPSite.RootWeb.title "`n"
    }

No comments:

Post a Comment