Skip to content

Instantly share code, notes, and snippets.

@RyanHirsch
Created October 25, 2013 13:48
Show Gist options
  • Save RyanHirsch/7154977 to your computer and use it in GitHub Desktop.
Save RyanHirsch/7154977 to your computer and use it in GitHub Desktop.
Toggle SharePoint feature on site and all children
Function TraverseWebs($url, $feature)
{
$web = Get-SPWeb $url
foreach($child in $web.Webs)
{
ToggleFeature $web $feature
if($child.Webs)
{
TraverseWebs($child.Url)
}
}
}
Function ToggleFeature($web, $featureName)
{
$results = Get-SPFeature -Web $web | Where-Object { $_.DisplayName -eq $featureName }
if($results) {
Disable-SPFeature -Identity $featureName -Url $web.Url -Confirm:$false
Enable-SPFeature -Identity $featureName -Url $web.Url
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment