Quickly Remove ALL Webs under a Site Collection Using PowerShell


I was cleaning up my demo site collection, and I needed to remove all subwebs… Here’s a quick one-liner of PowerShell to do exactly that.

Get-SPSite <SiteUrl> | Get-SPWeb -Limit All | ForEach-Object {Remove-SPWeb -Identity $_ -Confirm:$false}
</ShortestPostEver>
Advertisements

2 thoughts on “Quickly Remove ALL Webs under a Site Collection Using PowerShell

  1. Ryan Dennis

    Hey Grant,

    This will not actually remove the rootweb, it will actually give you a warning/error. For a situation where you want to quickly cleanup all of the subwebs leaving the rootweb intact, it works great!

    Ryan

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s