How to delete SharePoint Online site using PowerShell

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.

Delete SharePoint Online site collection using PowerShell

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
sharepoint online delete site collection powershell
sharepoint online delete site collection powershell

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

sharepoint online delete site collection powershell
sharepoint online delete site collection powershell

Permanently delete SharePoint Online site PowerShell

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

Restore SharePoint Online Site from Recycle Bin using PowerShell

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
restore site collection sharepoint online powershell
restore site collection SharePoint online powershell

Read some SharePoint PowerShell cmdlets examples:

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.

>