Monday, August 5, 2013

Enable-Activate SharePoint Feature on all Site Collections using PowerShell

Ever wanted to enable a feature on all site collections in a SharePoint environment? Well, To activate a SharePoint feature on a particular site, we use: Enable-SPFeature cmdlet.

Enable-SPFeature –Identity "FeatureName" –url http://SharePoint-site-URL  
Recently I had to enable a Branding feature on all sites to apply new corporate branding with the following one liner: PowerShell script.
#activate feature on all sites in all web applications in the farm
Get-SPWebApplication | Get-SPSite -Limit ALL | ForEach-Object{ Enable-SPFeature -URL $_.url -Identity (Feature Name or URL) -Confirm:$FALSE } 

Here is the E.g. for above script:
Get-SPWebApplication "" | Get-SPSite -Limit All | Get-SPWeb -Limit ALL | ForEach-Object { Enable-SPFeature  "fead7313-ae6d-45dd-8260-13b563cb4c71" } -Url $_.Url
Here the PowerShell script gets all sites under the web application and activates the feature.

To get the Feature GUID you can use:
Get-SPFeature | Where {$_.DisplayName -eq "FeatureName"} | Select ID
In total, The below script iterates through all web applications, site collections, checks whether the feature is already activated. If not, enables feature on all sites .
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Get all Site collections
$SiteColl = Get-SPWebApplication "" | Get-SPSite -Limit All 
#Target Feature to Activate
$FeatureToActivate = Get-SPFeature | Where {$_.DisplayName -eq "FeatureName"} 

#Iterate through each site collection
ForEach($Site in $SiteColl)
  #Check if Feature is already activated
  $FeatureActivated = Get-SPFeature -site $site | Where {$_.displayname -eq $FeatureToActivate.DisplayName}
  if ($FeatureActivated -ne $null)
		Write-Host "Feature already activated at: "$site.Url
		#Activate the feature
		Enable-SPFeature -Identity $FeatureToActivate -URL $Site.URL -Confirm:$False
		Write-Host "Activated Feature on "$site.Url

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.

Check out these SharePoint products:

No comments :

Post a Comment

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...