Deleting Sites from SharePoint Online recycle bin


SharePoint Online automatically clears out it’s recycle bin 30 days after you create a site. This might not be a problem in a live environment, but when you are using SharePoint Office for testing or developing, you will find yourself creating and deleting sites over and over.

If you delete a site, and then create the site with the same name, SharePoint will ask you if you wish to permanently delete the site from the recycle bin so that you can re-create the site.

However if you need to create a new site that name didn’t already exist, and you are running out of resources or available space there isn’t a way to delete the sites from the recycle bin within the Online Central Admin recycle bin. If you look below, you will see that you can click on a Site, which just enables the Restore Deleted items. There is nowhere, where you can delete it permanently.

The only option you have is using PowerShell. If you haven’t connected PowerShell to SharePoint Online before, I recommend you read my previous blog post https://cann0nf0dder.wordpress.com/2013/11/08/powershell-and-connecting-to-sharepoint-online/

You need to use Remove-SPODeletedSite –Identity https://myonlinesite.sharepoint.com to remove a site. My following script will clear the recycle bin for you.

$username = <Your userName>
$password = <Your Password>
$siteAdminURL = "https://myonlinesite-admin.sharepoint.com"
Import-Module Microsoft.Online.SharePoint.PowerShell –DisableNameChecking
$securePassword = ConvertTo-SecureString $password –AsPlainText –force
$O365Credential = New-Object System.Management.Automation.PsCredential($username, $securePassword)
Connect-SPOService -Url $siteAdminUrl -Credential $O365Credential

Get-SPODeletedSite | foreach {
Write-host "Deleting " $_.Url
Remove-SPODeletedSite –Identity $_.Url –Confirm:$false
}
Disconnect-SPOService
Advertisements