In this tutorial, we will discuss how to delete SharePoint Online site using PowerShell. Also, we will see how to restore a SharePoint Online site from the recycle bin using PowerShell. And we will see how to permanently delete SharePoint site using PowerShell.
PowerShell is very useful in SharePoint Online as well as for SharePoint on-premise version.
If you are new to SharePoint Online PowerShell, then read Connect to SharePoint Online Site using PowerShell.
SharePoint Online tutorial contents:
We can use Remove-SPOSite PowerShell cmdlets to move the SharePoint Online site or site collection to the recycle bin.
This command will not delete the site collection permanently instead it will just move to the recycle bin in SharePoint Online.
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.
Below is the PowerShell command to remove SharePoint 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
Once you run the command, the site will be moved to the recycle bin. See the fig below:
If you want to permanently delete the SharePoint Online 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 SharePoint Online site from the 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
Read some SharePoint PowerShell cmdlets examples:
- SharePoint Online external sharing tutorial
- How to Retrieve SharePoint Online Current Site Title and URL using PowerShell
- How to get all users from SharePoint site collection using PowerShell
- SharePoint 2013 backup and restore using PowerShell
- SharePoint Online storage limits
- Hide Document Library or Lists using PowerShell in SharePoint 2016/2013
- How to send email using PowerShell in Office 365
- Create and delete subsites under SharePoint site collection programmatically using PnP CSOM
- How to change SharePoint Site Collection Administrator
Here, we learned how to delete SharePoint Online site collection using PowerShell and also how to permanently delete a site using PowerShell from the recycle bin.
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 EnjoySharePoint.com