The recent release of Service Pack 1 for SharePoint 2010 included the Site Recycle Bin for restoring deleted sites. However, what if you deleted a whole Site Collection? Well, Service Pack 1 comes packaged with 3 new PowerShell commands to handle just that:
- Get-SPDeletedSite
- Restore-SPDeletedSite
- Remove-SPDeletedSite
A Site Collection at https://portal.contoso.com/sites/HR was recently deleted by accident. Let’s use our best friend, PowerShell, to get that site back and keep the news (and headache) from our SQL DBAs.
Open up the SharePoint 2010 Management Shell with an account that has the proper SPShellAdmin rights. Next, use Get-SPDeletedSite to locate the deleted Site Collection:
Get-SPDeletedSite -Identity /sites/HR
Notice how we have to use a server relative URL for the Identity parameter and not the full URL like we typically use when using this parameter with Get-SPSite.
This is also assuming we know or remember the server relative URL that was deleted. In case you are forgetful, like me, we can replace the Identity parameter with ContentDatabase, WebApplication, or even conduct a date range with DateTimeFrom and DateTimeTo:
Now, to restore the Site Collection run the Restore-SPDeletedSIte command with the same server relative URL Identity parameter:
Restore-SPDeletedSite -Identity /sites/HR
However, we can simplify this a little further when performing this next time by piping the result from Get-SPDeletedSite directly to Restore-SPDeletedSite like so:
Get-SPDeletedSite -Identity /sites/HR | Restore-SPDeletedSite
The ability to put the restore of both Sites Collections and Sites into the users and admins hands will surely make DBAs, Farm Admins, Help Desk, and a lot of others sleep much easier at night!
Pingback: Restore a Deleted Site Collection in SharePoint 2010 SP1 « SP2010 Blog
After the site collection has been deleted how long do you have until you actually use the powershell commands to restore it.
Is there a default time frame that you have to restore. Does the site actually become not restorable after a certain time frame.
Also is it restoring it from the content database?
Thank you in advance
George
just saved my butt. unfortunetly I had deleted the site collection then recreated it with the same URL’s and realized that I had deleted some data in the original site. I tried to restore over the top of the site I just created but it errored out. So I had to delete the site I just created. I was worried that I would overwrite the original deleted site that had data I wanted. Luckily it did not, it just made another instance of a deleted site collection so I had two to pick from. When you restore, use the Site ID with the identity switch so that you get the right instance of the deleted site collection. ie: Restore-SPDeletedSite -Identity 35eb2162-824b-4f58-a7b3-837c0879c502
i have deleted hostheader sitecollection. but when i type Restore-SPDeletedSite -Identity http://test.bpweb.bp.com/ it throws cannot find spdeletedstieobject or url.
How it works in case of hostheader site collection ??
Try using the WebApplication parameter with it too “-WebAppication ”
If that doesnt work, try Restore-SPSite -Identity -HostHeader