Tuesday, May 22, 2012

Restore a deleted site collection in SharePoint Server 2010 powershell script

Restore a deleted site collection in SharePoint Server 2010

In prior versions of SharePoint Server 2010, if a site collection (that is, an SPSite object) was accidentally deleted, there was not a direct way of restoring a specific deleted site collection. The only method to restore a deleted site collection was to restore the entire farm from a backup. This was costly and time consuming, and typically was not performed.
When a site collection is accidentally deleted in SharePoint Server 2010 with SP1, the deleted site collection is stored in the SPDeletedSite object, not the SPSiteobject. Therefore, to restore a deleted site collection, you must use the Restore-SPDeletedSite Windows PowerShell cmdlet or programmatically access the object model.

PowerShell script

This will restore all the deleted site the same location, if site already exists it wont, use -force to restore

if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null){

Add-PSSnapin "Microsoft.SharePoint.PowerShell"


foreach($deletedSite in Get-SPDeletedSite)
Write-Host $ deletedSite  ;
Restore-SPDeletedSite -Identity $deletedSite 

happy Coding ,
Power of PowerShell

No comments:

Post a Comment