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 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!
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!"
}
excellent write-up, thanks!