Connect to SharePoint Online and delete a SharePoint Site Collection and its Subsites

Scenario description

In the Office 365 Admin Center, when you delete a SharePoint site collection, it will be moved to the SharePoint Site Collection Recycle Bin where it will remain and can be restored for the next 30 days. Typically this is not a problem unless you want to reuse the SharePoint site collection name.

In this case, you would need to use PowerShell to permanently delete the Site Collection and all of its subsites.

Connect to SharePoint Online and delete a SharePoint Site Collection and its Subsites

To begin, you will need to load the SharePoint Online module to be able to run commands in PowerShell. You must also replace the url "https://contoso-admin.sharepoint.com" and use your SharePoint administrative site.
Import-Module Microsoft.Online.Sharepoint.PowerShell
$credential = Get-credential
Connect-SPOService -url https://contoso-admin.sharepoint.com -Credential $credential
This script will delete the SharePoint site collection. You must replace the url "https://contoso.sharepoint.com/sites/SiteCollectionName" with your Sharepoint Online URL and use the Site Collection Name that is to be deleted for this script to work properly.
Remove-SPOSite -Identity https://contoso.sharepoint.com/sites/SiteCollectionName -NoWait
This command will pause the script for 20 seconds before proceeding.
Start-Sleep -s 20

This script will permanently delete the SharePoint site collection after it is sent to the SharePoint Site Recycle Bin. You must replace the url “https://contoso.sharepoint.com/sites/SiteCollectionName” with your Sharepoint Online URL and use your Site Collection Name that is to be permanently deleted for this script to work properly.

Remove-SPODeletedSite -Identity https://contoso.sharepoint.com/sites/SiteCollectionName
Resources
Comments

No Comments