Interacting with Deleted SharePoint Artefacts using PowerShell

Background Information:

Since the introduction of Service Pack 1 for SharePoint 2010, Microsoft has made it possible for users to retrieve a deleted SharePoint Web or a Site Collection from the recycle bin. If a user goes and deletes a Web or a Site Collection from the SharePoint Interface, the web will be sent to the recycle bin for a period of 30 days, after which it will be disposed of automatically.  With this first Service Pack, Microsoft introduced a new Object to the SharePoint model called SPDeletedWeb or SPWebDeletedSite. This new object represents a deleted Web, and has a limited set of methods and properties available for it. As part of this Service Pack were also a few new PowerShell cmdlets that allow us to interact with these “half-alive” artefacts, allowing us to restore them to their former glory, or to send them out into the abyss forever.


The following list of PowerShell cmdlets were introduced as part of Service Pack 1 for SharePoint 2010:

  • Remove-SPDeletedWeb
  • Remove-SPDeletedSite
  • Get-SPDeletedWeb
  • Get-SPDeletedSite
  • Restore-SPDeletedWeb
  • Restore-SPDeletedSite

Now, something very important to take a good note of: You can only ever restore a Web or a Site Collection that was deleted through the web interface. If you used PowerShell (Remove-SPWeb or Remove-SPSite) to delete them, they are G-O-N-E, and there is no way for you to restore them but to use your backups.

Getting a Reference to a Deleted Web or Site Collection:

Using the Get-SPDeletedWeb or the Get-SPDeletedSite Powershell cmdlets, you can get a reference to a deleted web or site collection in your environment. Remember, this only works if you have SharePoint 2010 Service Pack 1 or higher (any flavour of SharePoint 2013 works). The way you’d normally go about restoring a deleted artefact is by specifying its URL. For example, if in my environment I have all my “secondary” Site Collections created under the “/sites/[…]” managed path, then I could retrieve a list of all my deleted Site Collections by calling the following PowerShell command:

Get-SPDeletedSite “/sites/*”

This command will return a collection of SPDeletedSite objects.


Restoring a Deleted Web or Site Collection:

Assuming you have a web or a site collection that has been deleted through the web interface, meaning that is it now a SPDeletedWeb or a SPDeletedSite object. To restore it using PowerShell you need to use the Restore-SPDeletedSite or the Restore-SPDeletedWeb cmdlet and pass it the URL of the object to restore, or a reference to it obtained by the Get-SPDeletedSite or Get-SPDeletedWeb cmdlet. The following Powershell command will restore the HR Site Collection

Restore-SPDeletedSite /sites/HR


Removing a Deleted Web or Site Collection:

Removing a deleted Site Collection or Web from the Recycle bin will delete it permanently from the SharePoint environment. This can be achieved by using the Remove-SPDeletedSite or the Remove-SPDeletedWeb PowerShell cmdlets. Just like for the restore operation, you can either pass it the URL of the deleted artefact or a reference to it. The following example will permanently delete the HR site collecton, which had been deleted through the Central Administration web interface.

Remove-SPDeletedSite /sites/hr


Leave a Reply

Your email address will not be published. Required fields are marked *