Monday, July 30, 2012

Delete or Restore SharePoint Recycle Bin Items based on Deleted Date using PowerShell

Requirement is to Restore all the Items deleted before last week from Recycle bin, which were already deleted from End-User Recycle bin (1st Stage Recycle bin).

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue 

$WebApp=get-spwebapplication ""

    foreach ($SPSite in $WebApp.Sites)
     #Contains both First Stage & Second Stage Recycle bin Items
     $SPRecycleBinItemCollection  = $SPSite.RecycleBin;
     #write-host "Processing Site: " $SPSite.RootWeb.Title "`n" 
     #write-host "Total No. of Items in Recycle bin: " $SPRecycleBinItemCollection.Count
        for ($i=$SPRecycleBinItemCollection.Count-1; $i -GE 0;  $i--)
             # check whether the Recycle bin Item is a SecondStageRecycleBin Item
              if($SPRecycleBinItemCollection[$i].ItemState -eq [Microsoft.SharePoint.SPRecycleBinItemState]::SecondStageRecycleBin)
               $deletedTime = $SPRecycleBinItemCollection[$i].DeletedDate;

                if ($selectedTime -LT $deletedTime)
                        $guid = $SPRecycleBinItemCollection[$i].ID;
                        write-host "Item Restored:" $SPRecycleBinItemCollection[$i].Title

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.

Check out these SharePoint products:

1 comment :

  1. Thank you, Thank you, Thank you! This script saved me hours of work.


Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...