Delete Webs Recursive with PowerShell


 

$web = Get-SPWeb "http://localhost/sites/webwithsubwebs/"

 

function RemoveSPWebRecursively([Microsoft.SharePoint.SPWeb] $web)

{

 

    $subwebs = $web.GetSubwebsForCurrentUser()

   

    foreach($subweb in $subwebs)

    {

        RemoveSPWebRecursively($subweb)

        $subweb.Dispose()

    }

    Remove-SPWeb $web -Confirm:$false

}

 

 

RemoveSPWebRecursively $web


Skip to main content