Friday, July 12, 2013

Search From Recycle bin



In this post we are going to see how we can search from recycle bin. Now out of the box there is no way to search an item from recycle bin and restore it.

The problem is when we have a lot of items in the recycle bin we need to page through and then find that item and then restore it.

Well there is a PowerShell that can come to rescue.

Here are simple steps to perform in PowerShell to find and restore the item.

$spSite= Get-SPSite $site

$web = $spSite.OpenWeb()

$files = $web.RecycleBin | ?{$_.Title -match “tst”}

foreach ($file in $files) 
{
Write-Host “Found $($file.Title)”
$web.RecycleBin.Restore($file.ID)
Write-Host “Restored $($file.Title)”
}

The script is pretty self explanatory. Get the site and then web object. Then take the recycle bin. It is first stage recycle bin. You can also take the second stage recycle bin from site object as well.

Then just search for item from recycle bin with title property. The above code returns all the items from recycle bin which has a tst as a match and then calls restore method to restore it to their respective locations.

If you know the exact name of an item, you can write that and that specific item will be restored. See the advantage, you do not need to search from pages by paging through them if you have huge amount of items residing in recycle bin.

I hope this helps.

No comments:




Share your SharePoint Experiences with us...
As good as the SharePointKings is, we want to make it even better. One of our most valuable sources of input for our Blog Posts comes from ever enthusiastic Visitors/Readers. We welcome every Visitor/Reader to contribute their experiences with SharePoint. It may be in the form of a code stub, snippet, any tips and trick or any crazy thing you have tried with SharePoint.
Send your Articles to sharepointkings@gmail.com with your Profile Summary. We will Post them. The idea is to act as a bridge between you Readers!!!

If anyone would like to have their advertisement posted on this blog, please send us the requirement details to sharepointkings@gmail.com