enable or disable a feature for all subsites

I have run into situations where I had to rapidly change features or other aspects of subsites across multiple site collections. How can you do that with PowerShell? It turns out to be quite easy. You don't even need a script. You can run a nested command. Here is the example on how to enable a feature on every site and subsite in the farm:


get-spsite|get-spweb | foreach-object {enable-spfeature -id hold -url $_.Url}
Similarly, you can disable any feature across all subsites and sites with this command:

get-spsite|get-spweb | foreach-object {disable-spfeature -id hold -url $_.Url -confirm:$false}

Using this logic, you can also change other elements on sites without writing a script.

Comments

Greg Zook said…
To activate a site collection feature is slightly different. Here is an example of how I enabled this for every site collection:
$webAppsFeatureId = $(Get-SPFeature -limit all | where {$_.displayname -eq "OfficeWebApps"}).Id
Get-SPSite -limit ALL |foreach{Enable-SPFeature $webAppsFeatureId -url $_.URL }

Popular posts from this blog

Exchange 2010 event errors 2601, 2604, 2501

Robocopy Error 31 A device attached to the system is not functioning

"The following factors also affect the level of access for" user with excess permissions