Delete and Restore Site Collection using PowerShell in SharePoint Online

SharePoint online powershell delete site collection

In this post we will discuss how we can delete and restore site collection using PowerShell in SharePoint online. If you are new to SharePoint Online PowerShell, then you can read an article on:


How to connect to SharePoint online site using SharePoint Online Management Shell?

We can use Remove-SPOSite PowerShell cmdlets to move the site collection to the recycle bin. This command will not delete the site collection permanently instead it will just move to the recycle bin.

Just to let you know that you must be a SharePoint Online global administrator and a site collection administrator to run the below cmdlet. Even if you are a SharePoint Online global administrator, it will not allow you to delete the site collection if you are not a site collection administrator.

Also you can read:

How to create index in SharePoint online list using CSOM .Net managed object model code?

Step by step develop workflows using visual studio 2015 as an add in and deploy to host web in SharePoint online?

Below is the PowerShell command to remove the site collection.

Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking

Connect-SPOService -Url https://onlysharepoint2013-admin.sharepoint.com -credential bijay@onlysharepoint2013.onmicrosoft.com

Remove-SPOSite -Identity https://onlysharepoint2013.sharepoint.com/sites/MySite -Confirm:$false

Restore Site Collection using PowerShell SharePoint Online
Restore Site Collection using PowerShell SharePoint Online

Once you run the command, the site will be moved to the recycle bin. See the fig below:

Delete Site Collection using PowerShell in SharePoint Online
Delete Site Collection using PowerShell in SharePoint Online

If you want to permantly delete the site from the recycle bin, you can run the below command:

Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking

Connect-SPOService -Url https://onlysharepoint2013-admin.sharepoint.com -credential bijay@onlysharepoint2013.onmicrosoft.com

Remove-SPODeletedSite -Identity https://onlysharepoint2013.sharepoint.com/sites/MySite -Confirm:$false

Similarly if you want to restore the deleted site collection from recycle bin, you can run the below PowerShell cmdlets.

Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking

Connect-SPOService -Url https://onlysharepoint2013-admin.sharepoint.com -credential bijay@onlysharepoint2013.onmicrosoft.com

Restore-SPODeletedSite -Identity https://onlysharepoint2013.sharepoint.com/sites/MySite

SharePoint online powershell delete site collection
SharePoint online powershell delete site collection


Hope this will be helpful.

Check out Best Alternative to InfoPath -> Try Now

You May Also like the Following SharePoint Online Tutorials:

About Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SharePointSky.com

View all posts by Bijay Kumar →