Every tenant I clean up for a client has the same leftovers: test sites from a pilot, a project site nobody opened in a year, and three copies of the same team site. Clicking through the admin center works for one site, but it’s slow, and it won’t permanently remove a group-connected site at all.
In this tutorial, we’ll delete a SharePoint site with PowerShell the safe way. Using a real throwaway site in my tenant, I’ll check it, delete it, find it in Deleted sites, restore it and purge it. You’ll also get the SharePoint Online Management Shell versions, group and hub site steps, and fixes for the errors that block a delete.
Quick answer: Connect to the admin center with Connect-PnPOnline, then run Remove-PnPTenantSite -Url https://spguides.sharepoint.com/sites/OldProject -Force. The site moves to Deleted sites for 93 days. To remove it for good, run Remove-PnPTenantDeletedSite -Identity <url> -Force. With the Management Shell, the same pair is Remove-SPOSite and Remove-SPODeletedSite.
How site deletion works in SharePoint Online
Deleting a site is a two-stage process. First the site moves from Active sites to Deleted sites, where SharePoint keeps it for 93 days. Only a second command, or the end of those 93 days, removes it permanently. If you’d rather click through it, my guide on deleting a SharePoint site from the admin center covers the browser steps.
| Task | PnP PowerShell | SharePoint Online Management Shell |
|---|---|---|
| Delete a site (to Deleted sites) | Remove-PnPTenantSite | Remove-SPOSite |
| List deleted sites | Get-PnPTenantDeletedSite | Get-SPODeletedSite |
| Restore a deleted site | Restore-PnPTenantSite | Restore-SPODeletedSite |
| Delete permanently | Remove-PnPTenantDeletedSite | Remove-SPODeletedSite |
Deleting a site removes everything in it: libraries, lists, pages, permissions and subsites. Tell the site owners before you run anything, so they can move what they still need.
Before you start: permissions and connection
You need the SharePoint Administrator role or higher. For Remove-SPOSite, Microsoft also says you must be a site collection admin on the site. I use PnP PowerShell in PowerShell 7 with my own Entra ID app registration; if it isn’t set up yet, follow installing PnP PowerShell for SharePoint Online first.
Connect to the admin center URL, not the site itself, because every cmdlet here works on tenant-level data. My post on connecting to SharePoint Online using PowerShell explains the sign-in options.
# Admin center URL + your own Entra ID app registration
$adminUrl = "https://spguides-admin.sharepoint.com"
$clientId = "00000000-0000-0000-0000-000000000000" # your app's client ID
Connect-PnPOnline -Url $adminUrl -ClientId $clientId -Interactive
For this walkthrough I created a throwaway communication site called SPGDemo Delete Test. Provisioning with -Wait took more than a minute and a half in my tenant:
New-PnPSite -Type CommunicationSite `
-Title "SPGDemo Delete Test" `
-Url "https://spguides.sharepoint.com/sites/SPGDemoDeleteTest" `
-Lcid 1033 `
-TimeZone UTCMINUS0500_EASTERN_TIME_US_AND_CANADA `
-Wait
Check the site before you delete it
I never delete a site blind. One Get-PnPTenantSite call tells me whether the site is connected to a Microsoft 365 group, is a hub, is attached to Teams, or is under a hold, and each of those changes how the delete works:
$siteUrl = "https://spguides.sharepoint.com/sites/SPGDemoDeleteTest"
Get-PnPTenantSite -Identity $siteUrl |
Select-Object Title, Url, Template, Status, GroupId, IsHubSite,
IsTeamsConnected, HasHolds, LockState |
Format-List