With our custom branding solution deployed to the SharePoint farm, we need to activate the site collection feature. The simplest method to activate the site collection feature on all site collections is using PowerShell.
Follow these steps to activate the feature on each site collection in the farm:
SiteCollectionBranding
feature ID to a PowerShell variable, using the following command:$brandingFeatureId = [GUID]"19e46226-efb9-4761-b09a-cb8711fd503a"
Get-SPWebApplication
Cmdlet to get the content web applications and iterate through them as follows:foreach ($webApp in (Get-SPWebApplication))
foreach ($site in $webApp.Sites)
if ($site.CompatibilityLevel –eq 15)
SiteCollectionBranding
feature is in the collection of activated features on the site collection. If the feature is not activated, add it to the collection as follows:if ($site.Features[$brandingFeatureId] -eq $null) { $site.Features.Add($brandingFeatureId) }
Dispose
method to discard the SPSite
object.$site.Dispose()
In this recipe, we retrieved all of the content web applications with the Get-SPWebApplication
Cmdlet. For each web application we then iterated through each site collection in the Sites
property. Lastly, we checked to ensure the site collection feature was activated on each site collection.
Adding or removing features is accomplished by adding or removing them from the collection of features exposed with the Features
property of the web application, site collection, or site.
Activating the site collection feature on all site collections can also be done with code using the server-side object model. Follow these steps to activate the site collection feature with code using the server-side object model:
SiteCollectionBranding
feature ID to a variable as follows:var featureBrandingSiteCollectionId = new Guid("19e46226-efb9-4761-b09a-cb8711fd503a");
foreach (SPWebApplication webApp in SPWebService.ContentService.WebApplications)
foreach (SPSite site in webApp.Sites)
if (site.CompatibilityLevel == 15)
SiteCollectionBranding
feature is in the collection of activated features on the site collection. If not, add the feature to the collection as follows:if (site.Features[featureBrandingSiteCollectionId] == null) site.Features.Add(featureBrandingSiteCollectionId);
18.118.9.197