Programmatically applying themes to Sharepoint subsites
So as I’ve discovered, one of the many differences between MOSS 2007 and WSS 3.0 is that WSS does not allow you to change the theme of any or all of the subsites from the GUI.
This has to be done programmatically, and we opted to use Powershell to do it. Here’s the code:
#Application of a given theme to a Sharepoint site and all sites beneath it
#First, load the Microsoft.Sharepoint objects into the Powershell space
[System.Reflection.Assembly]::Load(“Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral”)
#Open the target Sharepoint site (Replace oursharepointsite with your respective URL)
$site = new-object Microsoft.SharePoint.SPSite(“https://oursharepointsite”);
#Open the top level web
$siteweb = $site.OpenWeb();
#Enumerate each subsite in the allwebs collection, and apply the chosen theme to each one
foreach ($spweb in $site.allwebs)
{
write-output ($spweb.theme + ” ” + $spweb.title);
$spweb.ApplyTheme(“YourNewTheme”);
$spweb.Update();
#Write the name of the new theme as confirmation that the change was applied
write-output ($spweb.theme + ” ” + $spweb.title);
}
#Clean up
$siteweb.Dispose();
$site.Dispose();
Did you find this information helpful? If you did, consider donating to the author.