Monday, May 6, 2013

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

No comments:

Post a Comment