PowerShell Script to Permanently Delete SPDeleted Sites

When you want to Backup, Delete and Restore a SharePoint SiteCollection, you might want to completely remove it from SharePoint. Otherwise you get the error when restoring:

No content databases are available for this operation but the site collection is scheduled for deletion in at least one content database. Either wait for the deletion operation to complete or create a content database, and then try the operation again. To create a content database, click “Content databases” on the Application Management page, select the Web application to use, and then click “Add a content database”.

You could wait for the default 30 day retention period to cleanup the deleted sitecollections, or execute it immediately.

For a specific Web Application:

$wa = Get-SPWebApplication http://<WebApplicationUrl>
Get-SPDeletedSite -WebApplication $wa | Remove-SPDeletedSite

For all Web Applications:

Get-SPWebApplication | ForEach-Object{ 
	Get-SPDeletedSite -WebApplication $_.Url | Remove-SPDeletedSite 
}

Don’t forget to manually trigger the [Gradual Site Delete] Timerjobs, who will perform the real cleanup.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.