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?

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 of the deleted site (Otherwise, It gives 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:

  • Login to Office 365 Admin >> SharePoint Online Admin Center
  • Click on “Sites” >> “Deleted Sites” link from left navigation
  • Select the site from the list and click on the “Delete” button in the toolbar
  • Confirm 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 site from recycle bin

#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:

#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
}

Here is my 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://crescenttech.sharepoint.com"
$SiteURL = "https://crescenttech.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 is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

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

  • October 17, 2019 at 12:51 PM

    excellent write-up, thanks!

    Reply

Leave a Reply