Back to script samples page
Permanently Delete a SharePoint Site Collection

You can use this command to efficiently delete a site, and organizations instead of using the SharePoint Online Administration Center.

This sample script will enable you to connect to SharePoint Online and permanently delete a SharePoint Site Collection.

#Permanently Delete a SharePoint Site Collection.

#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 command 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
Downloaded 0 times
- - - - - (0)
Comments

No Comments