Remove-SPODeletedSite - Actually removing a SharePoint Online Site Collection (2024)

This post was most recently updated on August 31st, 2022.

3 min read.

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

Description

Table of Contents

Sometimes you need to get rid of a site collection you’ve created in SharePoint Online. The most typical example perhaps is 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).

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

Or perhaps you’re the glorious 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

Or an even more fun version:

Microsoft.SharePoint.Client.ServerException: Unknown Errorat Microsoft.SharePoint.Client.ClientRequest.ProcessResponseStream(Stream responseStream)at Microsoft.SharePoint.Client.ClientRequest.ProcessResponse()at Microsoft.SharePoint.Client.ClientRequest.ExecuteQueryToServer(ChunkStringBuilder sb)at Microsoft.SharePoint.Client.ClientContext.ExecuteQuery()

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

Why is it failing?

Well, after you remove the site collection, it actually goes to the second-stage recycle bin. The bad thing is, that this recycle bin is NOT accessible using a web browser but only by PowerShell. SharePoint Online still reserves 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!

Solutions

Luckily, there are 2 workarounds available for all the admin users. The new admin center and some great PowerShell commandlets to get rid of the deleted site!

Admin Center

Update: 5.12.2018:
In the Preview of the new SharePoint Online Administration console (https://[tenant]-admin.sharepoint.com/_layouts/15/online/AdminHome.aspx), there’s now the option to remove the sites via the GUI as well! These “Deleted Sites” can be found from the following address:

https://[tenant]-admin.sharepoint.com/_layouts/15/online/AdminHome.aspx#/recycleBin

So now there’s a GUI solution. Great – but see below for the PowerShell solution!

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 "[tenant-admin.sharepoint.com]"Remove-SPOSite -Identity "[url]" -NoWaitRemove-SPODeletedSite -Identity "[url]" -NoWait

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

How to completely 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 "[tenant-admin.sharepoint.com]"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.

Don’t be alarmed if this takes a long time – if you have dozens of sites in the second-stage recycle bin, it might easily take 15 minutes to finish the command.

That’s normal – get a coffee, and come back to check if the command finished successfully!

References

Check these out for some background info:

  • Author
  • Recent Posts

Antti K. Koskela

Developer / Speaker / Consultant at Koskila / Precio Fishbone / Norppandalotti Software Co / Alter - Experience Ideas Ltd

Antti Koskela is a proud digital native nomadic millennial full stack developer (is that enough funny buzzwords? That's definitely enough funny buzzwords!), who works as Solutions Architect for Precio Fishbone, building delightful Digital Workplaces.

He's been a developer from 2004 (starting with PHP and Java), and he's been working on .NET projects, Azure, Office 365, SharePoint and a lot of other stuff. He's also Microsoft MVP for Azure.

This is his personal professional (e.g. professional, but definitely personal) blog.

Latest posts by Antti K. Koskela (see all)

  • How to generate Certificate-Signing Requests using OpenSSL - June 18, 2024
  • Home Assistant 2024.4 changes weather forecasts – what to do? - June 11, 2024
  • External path “**” cannot have more than one “*” wildcard with vite? - June 4, 2024

41vote

Article Rating

Posts Related to "Remove-SPODeletedSite - Actually removing a SharePoint Online Site Collection":

  • Opening a web part page in maintenance mode
  • How to resolve the error "The alias is being used by another group in your organization"
  • Disabling Delve/MySite redirection from SharePoint Site Collections
Remove-SPODeletedSite - Actually removing a SharePoint Online Site Collection (2024)

References

Top Articles
Latest Posts
Article information

Author: Rueben Jacobs

Last Updated:

Views: 5917

Rating: 4.7 / 5 (57 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Rueben Jacobs

Birthday: 1999-03-14

Address: 951 Caterina Walk, Schambergerside, CA 67667-0896

Phone: +6881806848632

Job: Internal Education Planner

Hobby: Candle making, Cabaret, Poi, Gambling, Rock climbing, Wood carving, Computer programming

Introduction: My name is Rueben Jacobs, I am a cooperative, beautiful, kind, comfortable, glamorous, open, magnificent person who loves writing and wants to share my knowledge and understanding with you.