This command came about as a result of wanting to be able to reset the theme of a web site when it was upgraded. I had created this code as part of the upgrade2 command and figured that I might as well pull it out into its own command so that it could be used independently of the upgrade command. I called this command gl-applytheme. Setting the theme is really simple – you just call the SPWeb object’s ApplyTheme() method and pass in the theme ID. The theme ID for OTB themes can be found in the SPThemes.xml file located in the ..\12\Layouts\Templates\[LCID] folder. The core code can be seen below:
The syntax of the command can be seen below:
C:\>stsadm -help gl-applytheme stsadm -o gl-applytheme Applies the specified theme to the specified site. Parameters: -url <url of the web to update> -theme <id of the theme to apply (see C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\Layouts\1033\SPThemes.xml for template IDs> [-recurse (applies change to all sub-webs)]
Here’s an example of how to set the theme for a web to it’s default:
Note that sub-sites of a site collection will use the theme specified for the root site collection unless explicitly set. This means that you can set the theme for an entire site collection by just setting the root without setting the sub-sites. If you pass in the recurse flag then it will set the theme for each sub-site explicitly which means that future changes to the root web’s theme will not affect the theme for sub-sites (this may or may not be what you want so make sure that you understand how this works).