Activate a 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 site collection feature in SharePoint, navigate to Site settings >> Site Collection Features >> Click on “Activate” next to the relevant feature.
How to Activate a Feature using PowerShell?
To activate a SharePoint feature on a particular site, we use Enable-SPFeature cmdlet.
Enable-SPFeature -Identity "FeatureName" -url https://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 "https://www.sharepoint.crescent.com" | 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 the feature on all sites.
SharePoint PowerShell to activate feature on all site collections
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#Get all Site collections
$SiteColl = Get-SPWebApplication "https://sharepoint.crescent.com" | 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
}
else
{
#Activate the feature
Enable-SPFeature -Identity $FeatureToActivate -URL $Site.URL -Confirm:$False
Write-Host "Activated Feature on "$site.Url
}
}
Launch the SharePoint Online Management Shell as an Administrator
2. Do Connect-PnPOnline –Url https://yourdomain.sharepoint.com/path/to/site -SPOManagementShell
3. Do Enable-PnPFeature –Identity “915c240e-a6cc-49b8-8b2c-0bff8b553ed3” -Scope Site –Force
Note: If Enable-PnPFeature is missing in PowerShell, do: Install-Module SharePointPnPPowerShellOnline
Please refer here : https://sharepoint.uservoice.com/forums/329214-sites-and-collaboration/suggestions/33237925-modern-page-ratings
Connect-PnPOnline –Url “https://yoursite” -SPOManagementShell
Enable-PnPFeature –Identity “915c240e-a6cc-49b8-8b2c-0bff8b553ed3” -Scope Site –Force
How would you do this for SharePoint Online?
Here you go: How to Activate a Feature in SharePoint Online using PowerShell?
We have a feature that is installed on three web applications on a single SharePoint farm however we can have only one of the 3 activated at any time and we need to periodically change which is active for testing purposes. Because this happens randomly and potentially more than once a day we don’t want to have to keep pestering our SP admin so we would like to script the changes and set it up so others can run the script. As a result I was thinking we could set up a windows scheduler task/s which run/s a PowerShell script and then we enable PSRemote and potentially run the task from multiple places using PowerShell as well. If you could confirm this is doable and if possible an initial go at the server side feature activation/deactivation script it would be appreciated. I was thinking the script would initially deactivate them all and confirm this and then activate the selected one by some sort of parameter that is passed in ie. the web application path etc. Thank you in advance for your help. Mat