Tuesday, June 13, 2017

How to Delete Subsite In SharePoint 2013 using PowerShell

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="Parent Web Url"

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

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

No comments:

Post a Comment