Recently I deployed a custom branding feature stapler for one of my customers migrating from 2007 to 2010. As part of the branding feature we had custom layouts and design on the My Site host and user personal sites. New personal content sites created automatically had some custom branding applied by swapping out master pages and adding some linked CSS style sheets to the Style Library.
The solution works great for new personal sites on creation, but migrated sites still had the old look and feel. I wrote the branding feature in a way that it is visible to users and can be activated on a site (sp-web). Since I’m not about to go activate the feature manually on litterally thousands of sites, I got a handy script to do it for me! Big thanks to my college Donal Conlon on this one, Principle Consultant and all around rock star at my company Jornata.
You first need to generate an xml file containing all the sites you want to work with. I’m sure there’s some PowerShell that would do the same thing but I already know this stsadm command will work.
stsadm -o enumsites -url http://mysitehosturl > mysites.xml
Once you have this XML file, feed it into this PowerShell scripts to activate your site feature. Note you’ll need to know the feature’s GUID in order to make it work.
## Enable feature on all sites in site collection
## This script takes the output from the stsadm -o enumsites command (xml)
## Run 'stsadm -o enumsites' first to generate the xml which lists all the site collections for the database
function ActivateFeature([string]$url){
$featId = "7a8597ff-67a7-473e-b2f5-46d5b504643b"
$feat = "BrandingTheme_MasterPageDeploymentFeature"
$site = Get-SPSite $url
$site | Get-SPWeb -limit all | ForEach-Object {
if (!$_.Features[$feat]) {
#Get-SPFeature -Identity $feat | Write-Host $_.Enabled
try{
Enable-SPFeature -Identity $feat -Url $_.Url
}
catch{
Write-Host "Feature may already enabled"
}
}
}
}
Write-Host "Getting sites xml file..."
1$config = Get-Content $args[0]
if($config -eq $null -or $err)
{throw "unable to read xml file. Use stsadm.exe -o enumsites to generate xml"}
Write-Host "Number of site collections: " $config.Sites.Count
[System.Xml.XmlNodeList] $navElements = $config.SelectNodes("/Sites/Site")
foreach ($navElement in $navElements)
{
$url = $navElement.GetAttribute("Url")
Write-Host "Appling branding to $url"
ActivateFeature $url
}
Download the PowerShell script in a .zip file here.
Alternatively you could use SharePoint Manager 2010 to activate the feature without needing to browse to the site. This is still a very manual process but a great tool as you can see hidden features as well which you can’t view in the UI.







