Activate Feature on All Sites in SharePoint using PowerShell

In some scenarios, you may have to activate a feature for all sites or site collections in SharePoint. In my case, I had to activate the “Open In Client” feature of SharePoint to disable browser-based editing for all site collection in a SharePoint web application. This blog post will show you how to use PowerShell to activate a feature on all SharePoint sites at once. This is a very handy trick if you want to activate a feature across your entire farm.

How to Activate a Feature in SharePoint?

To activate a site collection feature from SharePoint web UI, You can navigate to Site settings >> Site Collection Features >> Click on “Activate” next to the relevant feature.

Activate Feature on All Sites in SharePoint using PowerShell

Pretty easy enough through the UI, isn’t it? Well, If you have to do the same for dozens of site collections in the web application, PowerShell is the perfect solution.

Activate feature for all site collections in SharePoint

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Configuration Parameters
$WebAppURL="https://portal.crescent.com/"
$FeatureName="OpenInClient" #Feature Folder Name

#Get all site collections of the web app and iterate through
$SiteColl= Get-SPSite -WebApplication $WebAppURL -Limit ALL
Foreach($Site in $SiteColl)
{ 
 #Get the Feature ID from Feature Name
    $Feature = Get-SPFeature -Site $Site.Url | Where {$_.DisplayName -eq $FeatureName}
 
 #If Feature Found
 if($Feature -ne $null)
    {
       #Check if the Feature is activated already
       if (Get-SPFeature -Site $Site.Url | Where {$_.ID -eq $Feature.Id})
       {
         Write-Host $FeatureName "is already activated at " $Site.Url -f Yellow
        }
       else
       {
       #Activate the Feature
       Enable-SPFeature -identity $Feature.ID -URL $Site.URL
       Write-Host "Feature Activated on "$site.URL -f Green   
  }
 }
 else
 {
      Write-Host "Feature Name doesn't exist:"$FeatureName -f Red
 } 
}

This PowerShell script activates the feature on all site collections.

You can also use this one-liner to activate a feature on all site collections: (No error handling, however!)

Get-SPSite -Limit All | foreach {Enable-SPFeature "0561d315-d5db-4736-929e-26da142812c5" -url $_.URL } 

SharePoint: activate a feature on all sites

Consider a scenario, where you have to activate a site level (web) feature on 100’s of sites under a site collection, which is quite common. In my case, I had to activate Nintex Workflow 2013 feature on all subsites within a particular site collection.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Configuration Parameters
$SiteCollURL="https://portal.crescent.com/"
$FeatureID="0561d315-d5db-4736-929e-26da142812c5" 

#Get the Feature
$Feature = Get-SPFeature | Where {$_.ID -eq $FeatureID}

#If Feature Found
if($Feature -ne $null)
{     
    #Get all sites under the collection and loop through
    $Site= Get-SPSite $SiteCollURL
    Foreach($Web in $Site.AllWebs)
    {
  #Check if the Feature is activated already
       if (Get-SPFeature -Web $web.Url | Where {$_.ID -eq $FeatureId})
       {
         Write-Host $FeatureID "is already activated at " $Web.Url -f "Blue"
        }
       else
       {
           #Activate the Feature
           Enable-SPFeature -identity $FeatureID -URL $Web.URL
           Write-Host "Feature has been Activated on "$Web.URL -f "Green"
       }
    }
}
else    
{
    Write-Host "Feature doesn't exist:"$FeatureID -f "Red"
}

This script activates feature for all sites in SharePoint.

Salaudeen Rajack

Salaudeen Rajack - SharePoint Expert with Two decades of SharePoint Experience. Love to Share my knowledge and experience with the SharePoint community, through real-time articles!

Leave a Reply

Your email address will not be published. Required fields are marked *