Delete site collection

Remove-SPODeletedSite – Actually removing a SharePoint Online Site Collection

This post describes the actual, working and fast process of removing a site collection in SharePoint Online using the Remove-SPODeletedSite commandlet in SharePoint Online Management Shell (a flavor of PowerShell).


Sometimes you need to get rid of a site collection you’ve created in SharePoint Online. The most typical example perhap being removing the team site created for a group of people working together. That’s pretty simple and there are a few ways of doing that. For example, you might just go ahead, and delete the site from Site Settings (see below).

"Delete this site" on SharePoint Online
“Delete this site” on SharePoint Online – by the way, never use this, if there’s even a 1% you might want your data back! You might never get it.

Or maybe you’re a smart admin, and you go and remove it from the SharePoint Administration (below).

Delete site collection
Delete site collection on SharePoint Administration

Or perhaps you’re the legendary IT Pro, simply love PowerShell, and you just run this:

Remove-SPOSite -Identity "[url]"

However, sometimes you need to recreate a new site using the same url as the one you removed – and that’s not going to be possible. No matter which way you try – PowerShell, API or even through the GUI. You’ll run into issues, something like this:

Unknown Exception

That’s descriptive, right? Doesn’t help you much, or tell what to do at all.

Why is it failing?

Well, after you remove the site collection, it actually goes to the recycle bin. The bad thing is, that this recycle bin is NOT accessible using web browser, but only by PowerShell. SharePoint Online still reservers that url for the site, though, so you can’t create a new one with the same url!

This will hold true until after 30 days, when the recycle bin is finally emptied. And boy, is that a long time to wait to be able to create a new site you’d need right now!

Luckily, there’s an easy workaround available for all the admin users: PowerShell commandlets to get rid of the deleted site!

Solution: Remove-SPODeletedSite -Powershell commandlet

PowerShell to the rescue! You can always remove the site collection using PowerShell. The cmdlets are something like this (replace the urls):

Connect-SPOService -Url "[]"
Remove-SPOSite -Identity "[url]" -NoWait
Remove-SPODeletedSite -Identity "[url]" -NoWait

And you’re done! You should be able to create the new site collection with the old url.

How to empty the second-stage site collection recycle bin?

Okay, so maybe you know there’s nothing you want to save from the deleted SharePoint Site Collections and you just want to remove all of them? Luckily, that’s easy. -See the code below!

Connect-SPOService -Url "[]"
Get-SPODeletedSite | Remove-SPODeletedSite

The code simply loops through your deleted sites and passes (“pipes”) all of them to Remove-SPODeletedSite. And boom! You have nothing in your second-stage site collection recycle bin.


Check these out for some background info:

The following two tabs change content below.

Antti K. Koskela

Solutions Architect / Escalations Engineer at Koskila / Norppandalotti Software / Valo Solutions
Antti Koskela is a proud digital native nomadic millenial full stack developer (is that enough funny buzzwords? That's definitely enough funny buzzwords!), who works as a Solutions Architect for Valo Intranet, the product that will make you fall in love with your intranet. Working with the global partner network, he's responsible for the success of Valo deployments happening all around the world. He's been a developer from 2004 (starting with PHP and Java), and he's been bending and twisting SharePoint into different shapes since MOSS. Nowadays he's not only working on SharePoint, but also on .NET projects, Azure, Office 365 and a lot of other stuff. This is his personal professional (e.g. professional, but definitely personal) blog.

1 thought on “Remove-SPODeletedSite – Actually removing a SharePoint Online Site Collection

Let me know your thoughts!