How to Delete Subsite in SharePoint using PowerShell?

How to delete a subsite in SharePoint 2013 / 2016?

If you’re administering a SharePoint site, there may come a time when you need to delete a subsite. This can be done in just a few easy steps. This blog post will show you how to delete a subsite in SharePoint. We’ll also show you how to use PowerShell to delete a subsite!

To delete a subsite in SharePoint 2013, Navigate to Site Settings >> Click on the “Delete this site” link under the “Site Actions” group. sharepoint 2013 powershell remove subsite
That takes you to the “Delete this site” page. Click on the “Delete” button and confirm site deletion. 

delete subsite sharepoint 2013 powershell

So simple, huh?

To restore deleted subsite in SharePoint 2010(sp1) or in SharePoint 2013, Just go to your Site collection recycle bin!

Delete all subsites in SharePoint using PowerShell

Why do we need to use PowerShell while deleting subsites from SharePoint 2013 web UI is relatively simpler? Well, If you try to delete a subsite that has its subsites, You’ll end up in Error!

SharePoint doesn’t allow you to delete a site with its sub-sites (But You can delete a site collection and all its subsites in a single click from web UI by following the above instructions!). In other words, You cannot delete a SharePoint Subsite with one or more child subsites. You’ll have to individually remove each and every child subsite prior to removing the parent subsite.

Sorry, something went wrong

There was a problem deleting Web site “/Subsite”. Sites that have subsites or certain apps can’t be deleted. Please try again after deleting all subsites and removing the apps.
cannot delete sharepoint subsite
So, to delete a site with subsites in SharePoint, first, we have to delete all child subsites and then delete the parent site. What if you have a large number of subsites? Well, here is where PowerShell comes to the rescue.

Using content and structure is one way as in Delete Site with Subsites in SharePoint – Quick Way, It needs Publishing feature to be turned on. So, let’s utilize PowerShell to delete subsite in SharePoint 2013.

Delete a Subsite using PowerShell:

$SiteURL = ""
#Get the site
$web = Get-SPWeb $SiteURL
#Delete the subsite

Delete all subsites in SharePoint 2013 using PowerShell (Delete All Child Webs)

To remove a subsite in SharePoint 2013, use this PowerShell script. It basically scans and removes all subsites recursively.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

Function Remove-ChildSites([Microsoft.SharePoint.SPWeb]$Web)
 Foreach($ChildWeb in $Web.Webs)
  #Call the function recursively TO DELETE all sub-childs
    Write-host Removing web $Web.Url
    #Remove the web
 Remove-SPWeb $Web -Confirm:$false 


#Get the Parent Web
$ParentWeb= Get-SPWeb $ParentWebURL

#Call the function to remove all child webs
Remove-ChildSites $ParentWeb

Salaudeen Rajack

Salaudeen Rajack - SharePoint Expert with Two decades of SharePoint Experience. Love to Share my knowledge and experience with the SharePoint community, through real-time articles!

2 thoughts on “How to Delete Subsite in SharePoint using PowerShell?

  • I didn’t know about the subsite problem – glad I checked here first. Thank you!

  • Very nice script -thank you


Leave a Reply

Your email address will not be published. Required fields are marked *