Monday, January 9, 2017

Delete all subsites (All Child Webs) - SharePoint 2013 and PowerShell

Error: 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.


Solution:
Run PowerShell command
 
 
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
  Remove-ChildSites($ChildWeb)
 }
    Write-host Removing web $Web.Url
  
    #Remove the web
 Remove-SPWeb $Web -Confirm:$false
}
 
$ParentWebURL="http://portal/site/"
 
#Get the Parent Web
$ParentWeb= Get-SPWeb $ParentWebURL
 
#Call the function to remove all child webs
Remove-ChildSites $ParentWeb
 
 

No comments:

Post a Comment