0

I want to delete all webs and subwebs like this,

Add-PSSnapin Microsoft.SharePoint.Powershell

Get-SPWebApplication https://portal.fruits.com   | Get-SPSite -Limit All  | Get-SPWeb -Limit All | where {$_.Url -Match "crates"}  | ForEach-Object  {

        Remove-SPWeb $_ -Confirm:$false
}

How to delete subwebs and there webs here ?

6
  • I think you can just Pipe everything into the Remove-SPWeb command. Are you getting any errors with what you listed above?
    – Choggo
    Commented Feb 2, 2015 at 13:50
  • It looks like for you could be suitable just to delete the site collection. Or do you need to delete all subsites from certain level?
    – luccio
    Commented Feb 2, 2015 at 13:59
  • @luccio there's a filter applied near the end, so it's just some specific sub-sites
    – Choggo
    Commented Feb 2, 2015 at 14:00
  • 3
    This will need a recursion. if a web has sub web underneath, it can't be deleted. Commented Feb 2, 2015 at 14:05
  • Add order by url length decreasing
    – Choggo
    Commented Feb 2, 2015 at 15:39

1 Answer 1

1

So as to not leave this unanswered, the PowerShell below should clean up all sites that match the "crates" filter you specified.

Get-SPWebApplication https://portal.fruits.com | Get-SPSite -Limit All  | Get-SPWeb -Limit All | where {$_.Url -Match "crates"} | Sort-Object { $_.Url.Length } -Descending | Remove-SPWeb

I tested here using -whatif and the sort order solved the recursion requirement that Yousuf mentioned.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.