Friday, July 10, 2015

Restore Deleted Items from Recycle Bin in SharePoint Using PowerShell

How to restore deleted items from SharePoint recycle bin?

  • To restore deleted items, Click on "Recycle Bin" link on the Quick Launch.
  • Locate the object that you want to restore by Selecting the check box next to the object and then click Restore Selection.
    sharepoint restore from recycle bin powershell
SharePoint 2010 - Restore from recycle bin using PowerShell
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Configuration variables
$SiteURL="http://portal.crescent.com/sites/ops/"
$ItemName="Classifieds.xlsx" #Can be a List Name, File Name or ID of an Item

#Get Objects
$site = Get-SPSite $SiteURL
$RecycleBin = $site.RecycleBin

#Get the Item from Recycle bin
$Item = $RecycleBin | Where{$_.Title -eq $ItemName}

if($Item -ne $null)
{
 $Item.Restore()
 Write-Host "Item Restored from Recycle Bin!" -f DarkGreen
}
else
{
 Write-Host "No Item Found with the given name!" -ForegroundColor RED
}
This script restores given items from recycle bin.

Tips: How to find and restore all items deleted by a particular use? Use: $RecycleBin | Where { $_.DeletedBy -like "Domain\Account" }

Restore based on Object Type (such as List, Web, ListItem, etc)
What if you want to restore all deleted lists or deleted sub-sites from the Recycle bin? Here is the PowerShell script to restore all deleted lists from SharePoint 2013 recycle bin.
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Configuration variables
$SiteURL="http://portal.crescent.com"

#Get Objects
$site = Get-SPSite $SiteURL
$RecycleBin = $site.RecycleBin

#Get All deleted Lists from Recycle bin
$DeletedItems = $RecycleBin | Where{ $_.ItemType -eq "List"}
if($DeletedItems)
{
 Foreach($Item in $DeletedItems)
 {
  $Item.Restore()
  Write-Host "'$($Item.Title)' Restored from Recycle Bin!" -f DarkGreen
 }
}

PowerShell to restore all items from SharePoint Recycle bin:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

$SiteURL="http://portal.crescent.com/sites/operations"
$Site = Get-SPSite $SiteURL

#Get All Recycle bin items
$DeletedItems = $Site.RecycleBin

if($DeletedItems)
{
 foreach($Item in $DeletedItems) 
 { 
  $Site.RecycleBin.restore($Item.ID)
  Write-Host "Item restored:"$Item.Title
 }
}



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


Check out these SharePoint products:

No comments :

Post a Comment

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...