Various options to Delete Site or Sub Site or Restore in SharePoint 2013 Online and SharePoint Onpremise

Copying/Moving SharePoint 2010/2013 Designer Workflows

In this post, we will discuss how we can delete subsite using PowerShell as well as using the browser in SharePoint 2013 or SharePoint 2013 online.

Also, read:
SharePoint 2013 Image was not appearing in IE but appearing in Chrome and Firefox

– Get All Attachments From SharePoint 2013 List Item using Rest API

– Custom Ribbon Action and set the Customize Icon to Ribbon button in a SharePoint Hosted App

Using Browser:
Below steps will work same for SharePoint online as well as On premise.

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:

Various options to Delete Site or Sub Site or Restore in SharePoint 2013 Online and SharePoint Onpremise
Various options to Delete Site or Sub Site or Restore in SharePoint 2013 Online and SharePoint Onpremise

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.

Various options to Delete Site or Sub Site or Restore in SharePoint 2013 Online and SharePoint Onpremise
Various options to Delete Site or Sub Site or Restore in SharePoint 2013 Online and SharePoint Onpremise

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

Using PowerShell:
SharePoint OnPremise:
Below is the PowerShell command to delete a site collection which includes all sites and subsites under it.

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.

Add-PSSnapin “Microsoft.SharePoint.PowerShell”

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

SharePoint 2013 Online

We can use the Remove-SPOSite cmdlet to delete a site collection in SharePoint 2013 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:

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:

Various options to Delete Site or Sub Site or Restore in SharePoint 2013 Online and SharePoint Onpremise
Various options to Delete Site or Sub Site or Restore in SharePoint 2013 Online and SharePoint Onpremise

Restore Deleted Site Collection from Recycle Bin:
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:
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

Hope this will be helpful.


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 →