Delete and restore SharePoint site or subsite using Browser and PowerShell

This SharePoint tutorial, we will discuss how to delete and restore SharePoint site using PowerShell and by using browser.

The same way we can delete sites or subsites using browser and PowerShell in SharePoint 2013/2016 or SharePoint Online.

Delete SharePoint site using browser

Follow the below steps to delete site using a browser in SharePoint Online as well as SharePoint on-premises.

Open your SharePoint 2013 online site, then Click on settings -> Site Settings. Then from Site Actions click on “Delete this site”. This will show you a warning message, there click on the Delete button as shown in the fig below:

delete sharepoint site powershell

But here one problem will come if there will be subsites within that site. In that case, you might get the below error:

Sorry, something went wrong
There was a problem deleting Website “/MyTeamSubSite”. Sites that have subsites or certain apps can’t be deleted. Please try again after deleting all subsites and removing the apps.

delete sharepoint site using powershell

To solve the issue we have to delete the child subsite first and then we can be able to delete the parent site.

Delete SharePoint Site using PowerShell (on-premises)

Below is the PowerShell command to delete a site collection which includes all sites and subsites under it in SharePoint On-premises versions like SharePoint 2013/2016.

Add-PSSnapin “Microsoft.SharePoint.PowerShell”
Remove-SPSite -Identity “http://win-pfcp2dgt8di/sites/EnjoySharePoint/” -GradualDelete -Confirm:$False

Below is the PowerShell command to delete a particular subsite in SharePoint 2013/2016.

Add-PSSnapin “Microsoft.SharePoint.PowerShell”
$SiteURL = “http://win-pfcp2dgt8di/sites/EnjoySharePoint/MyTestSubSite/MySubSubSite/”
$web = Get-SPWeb $SiteURL
$web.Delete()

Delete SharePoint Online Site using PowerShell

We can use the Remove-SPOSite cmdlet to delete a site collection in SharePoint online. This command will not delete the site collection permanently rather the site collection will be moved to Recycle Bin from where we can restore the site collection using Restore-SPODeletedSite cmdlet.

Below is the PowerShell cmdlet to delete site collection in SharePoint Online.

Import-Module Microsoft.Online.SharePoint.Powershell -Verbose
Remove-SPOSite -Identity “https://onlysharepoint2013.sharepoint.com/teams/MyDeleteSiteColTest”

After executing this command, if you will open the Recycle Bin in SharePoint 2013 online admin center you will be able to see the deleted sites there like below:

delete sharepoint site collection

Restore Deleted Site Collection from Recycle Bin in SharePoint

If you want to restore the deleted site collection from the recycle bin then in the browser you can select the site and then click on Restore Deleted Items. It will restore the site collection. Otherwise, you can use the below PowerShell command.

Import-Module Microsoft.Online.SharePoint.Powershell -Verbose
Restore-SPODeletedSite -Identity https://onlysharepoint2013.sharepoint.com/teams/MyDeleteSiteColTest

Remove Site Permanently from Recycle Bin in SharePoint Online

We can use the Remove-SPODeletedSite cmdlet to permanently delete the site from recycle bin. After this, you will not be able to restore the site.

Import-Module Microsoft.Online.SharePoint.Powershell -Verbose
Remove-SPODeletedSite -Identity https://onlysharepoint2013.sharepoint.com/teams/MyDeleteSiteColTest

You may like following SharePoint site collection tutorials:

This SharePoint tutorial learned, how to delete the SharePoint site or subsite from the browser in SharePoint 2013/2016/Online. Also, we saw how to delete the site using PowerShell in SharePoint 2013/2016 or SharePoint Online.

We also learn, how to remove site permanently from Recycle Bin in SharePoint Online? How to restore deleted site collection from Recycle Bin in SharePoint Online using PowerShell.

Donwload Hub site pdf

Download SharePoint Online Tutorial PDF FREE!

Get update on Webinars, video tutorials, training courses etc.

>