Saturday, November 15, 2014

How to Delete Subsite In SharePoint 2013 using PowerShell

How to delete a subsite in SharePoint 2013?
To delete a subsite in SharePoint 2013, Navigate to Site Settings >> Click on "Delete this Site" link under "Site Actions" group. sharepoint 2013 powershell remove subsite
That takes you to the "Delete this site" page. Click on "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 we need to use PowerShell, while deleting subsites from SharePoint 2013 web UI is relatively simpler? Well, If you try to delete a sub-site which has its own 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 above instructions!). In other words You cannot delete SharePoint Subsite with one or more child subsites. You'll have to individually remove each and every child subsite prior removing 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 large number of subsites? Well, here is where PowerShell comes to 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, lets 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 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

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.

Check out these SharePoint products:

No comments :

Post a Comment

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...