Wednesday, September 3, 2014

Delete subsites within site collection using Powershell

Here i am going to give a script to delete all the webs within site collection. The script,

Get-SPSite  Your site collection URL| Get-SPWeb -Limit All | ForEach-Object {Remove-SPWeb -Identity $_ -Confirm:$false}

This script will access the rootweb also but it can't be deleted. To avoid this, try the below

$url = " Your site collection URL"
$subsites = ((Get-SPWeb $url).Site).allwebs | ?{$_.url -like $url +"/*"}


foreach($subsite in $subsites) { Remove-SPWeb $subsite.url }

No comments:

Post a Comment