I need a PowerShell script for activating a specific site collection feature in every site collection of mysite if not already activated.

How can this be done?

1 Answer 1


If the are all under a managed path you can do something like this:

$sites = Get-SPSite https://mysiteurl/* -Limit ALL
foreach($site in $sites){
    Enable-SPFeature "name or GUID here" -Url $site.Url 

This will throw errors on sites where the feature is already activated, but since it is PowerShell the execution will continue for the other sites. You could use ErrorAction SilentlyContinue on Enable-SPFeature to not get the error output

  • doesn't work for me. powershell doesn't throw any error .feature doesn't activate Jun 9, 2014 at 6:08
  • Do you pass in a correct URL base? Jun 9, 2014 at 7:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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