SharePoint Online: Delete Site Collection from Recycle Bin using PowerShell

Requirement: Delete Site Collection from recycle bin in SharePoint Online.

How to Delete SharePoint Online Site from recycle bin?

In this article, we will show you how to delete a site collection from the recycle bin in SharePoint Online. Deleting a site collection from the recycle bin permanently deletes a site collection, and the site cannot be restored without the help of Microsoft support. So, Before deleting a site collection from the recycle bin, make sure that you are absolutely certain that you want to delete it.

When we delete a SharePoint Online site collection, it goes to the Recycle Bin and stays there for 93 days. However, at times we may want to completely delete the site from recycle bin too for reasons such as:

  • We ran a shortage of storage quota, and we want to delete the site collection to obtain the space.
  • We need to create a new site collection with the same URL as the deleted site (Otherwise, It gives the error: New-SPOSite : A site already exists at URL https://yourtenant.sharepoint.com)

Permanently Delete Site Collection from Recycle bin

To delete a site permanently from the recycle bin in SharePoint Online, follow these steps:

  1. Login to Office 365 Admin >> SharePoint Online Admin Center.
  2. Click on the “Sites” >> “Deleted Sites” link from the left navigation.
  3. Select the site from the list and click on the “Delete” button in the toolbar.
  4. Confirm the delete operation in the prompt!
    sharepoint online delete site collection from recycle bin powershell

Let’s see the SharePoint Online PowerShell to delete site collection from recycle bin.

SharePoint Online: Delete Site Collection from Recycle Bin using PowerShell

Here is the SharePoint Online PowerShell to delete a site from recycle bin with the Remove-SPODeletedSite cmdlet:

#Define Parameter values
$AdminSiteURL = "https://crescent-admin.sharepoint.com/"
$DeletedSiteCollURL = "https://crescent.sharepoint.com/sites/DeletedSite"
 
#Connect to SharePoint Online
Connect-SPOService -url $AdminSiteURL -Credential (Get-Credential)

#Remove Deleted SharePoint Online Site Collection permanently
Remove-SPODeletedSite -identity $DeletedSiteCollURL -Confirm:$false

Permanently Delete All Site Collections from Recycle Bin in SharePoint Online:

Want to delete all sites from the recycle bin permanently? Here is the PowerShell to remove all deleted sites:

#Define Parameter values
$AdminSiteURL = "https://crescent-admin.sharepoint.com/"
 
#Connect to SharePoint Online
Connect-SPOService -url $AdminSiteURL -Credential (Get-Credential)

#Permanently Remove all Deleted Sites
Get-SPODeletedSite | ForEach {
Write-host "Deleting Site " $_.Url
#sharepoint online powershell delete site from recycle bin
Remove-SPODeletedSite -Identity $_.Url -Confirm:$False
}

This empties the tenant recycle bin in SharePoint Online. Here is another post on deleting SharePoint Online site collections: How to Delete a Site Collection in SharePoint Online using PowerShell?

SharePoint Online: Delete Site Collection from Recycle bin using PnP PowerShell

Let’s delete site collection from recycle bin SharePoint Online using PnP PowerShell:

#Config Variables
$TenantURL = "https://Crescent.sharepoint.com"
$SiteURL = "https://Crescent.sharepoint.com/sites/Customers"

#Connect to PnP Online
Connect-PnPOnline -Url $TenantURL -Credentials (Get-Credential)

#Get the Deleted Site from Recycle Bin
$DeletedSite = Get-PnPTenantRecycleBinItem | Where {$_.URL -eq $SiteURL}

#Check if site exists in recycle bin
If($DeletedSite)
{
    #sharepoint online powershell delete site collection from recycle bin
    Clear-PnPTenantRecycleBinItem -Url $SiteURL -Force
    Write-host -f Green "Site '$SiteURL' Deleted from Recycle Bin Successfully!"
}
Else
{
    Write-host -f Yellow "Could not find Site '$SiteURL' in Recycle Bin!"
} 

Salaudeen Rajack

Salaudeen Rajack - SharePoint Expert with Two decades of SharePoint Experience. Love to Share my knowledge and experience with the SharePoint community, through real-time articles!

One thought on “SharePoint Online: Delete Site Collection from Recycle Bin using PowerShell

  • excellent write-up, thanks!

    Reply

Leave a Reply

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