Remove SharePoint site from Tenant

Did you already mistyped a SharePoint site name and be stuck because you have to wait 30 days to create a new site? Did you select a Team Site instead of Communication Site? Where is the site that we need to delete Classic or Modern?

When you are trying to create a site with a name that already exists, SharePoint will create a new site but with different URL. If that site is not listed in the Active sites, most likely is on deleted sites but not eliminated from SharePoint.

Add Site

With the next PowerShell script, we’ll unlock the possibility to reuse the same Site name immediately on the SharePoint tenant. Note that we cannot revert from erasing the site from SharePoint.

$loginUrl   = "https://contoso-admin.sharepoint.com" #SharePoint Admin Center
$username   = "contoso@contoso.com"
$password   = "contoso"

$encpassword = convertto-securestring -String $password -AsPlainText -Force
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $encpassword

Connect-SPOService -Url $loginUrl -Credential $cred
$sites = Get-SPODeletedSite
foreach($site in $sites){
 #Remove all the Sites Collections deleted from the site
 #-Confirm:$false with this line will not ask to confirm the code
 Remove-SPODeletedSite -Identity $site -Confirm:$false
}
Disconnect-SPOService

Conclusion

When this script is finished, you can now create new site collections at the SharePoint Admin with any name that you want including the deleted sites.

One Comment

Leave a Reply

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