I want to activate a feature (scoped at site collection level)eg:Publishing Approval workflow in all web application. Require the powershell code. Thanks

3 Answers 3


Following is the sample PowerShell code. However, I have not tested it. But this should give you an idea how to do it:

#Get all the web applications
$webApplications = Get-SPWebApplication
#Loop through all the web applications
foreach($webApp in $webApplications)
    #Loop through all the site collections in a particular web application
    foreach($site in $webApp.Sites)
        #Activate the feature you want
        Enable-SPFeature -Identity $FeatureID -Url $site.url  -Confirm:$false 

You need to pass the feature Id of Publishing Approval workflow in the above code. One easy way to find the id of a feature is to use SharePoint Manager.


You could the following code....its not tested

     $thisFarm = SPFarm.Local; 
     $service = thisFarm.Services;     

     foreach ($webApp in $service.WebApplications) 

        foreach ($siteCollection in $webApp.Sites) 
     $feature = Get-SPFeature PublishingSite 
   Enable-SPFeature -Identity $feature -Url $siteCollection.Url -Confirm:$false

you can try this code, will enable feature to all site collections in a web application:

 $webApp = Get-SPWebApplication -Identity http://sp2010  

$webApp | Get-SPSite -limit all | ForEach-Object {Enable-SPFeature -Identity “FeatureName” -Url $_.Url}

  • Hi Waqas ,i added the below code in the script file. Add-PSSnapin Microsoft.Sharepoint.Powershell $webApp = Get-SPWebApplication -Identity cloudx-151-145:12345 $webApp | Get-SPSite -limit all | ForEach-Object {Enable-SPFeature -Identity “PublishingApprovalWorkflow” -Url $_.Url}. Am getting error as SP-Webapp,SP-Feature is not recognised cmdlet.
    – priya
    Jan 2, 2014 at 4:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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