[SharePoint 2013] Using PowerShell to Set the Theme Color Palette of a SharePoint Site

SharePoint 2013 includes a pretty useful theming engine that is light years ahead of previous versions of SharePoint. There is one caveat that is a bit annoying: you cannot apply the themes to certain types of sites through the web interface. For instance, you cannot set the theme color of the My Site host.

However, you can do this programmatically and through PowerShell. This example shows how to set the SharePoint theme palette for the My Site host:

Notes about this example:

  • “http://site/my” is the URL to the SharePoint site (SPWeb) that we are setting the theme for.

  • “/_catalogs/theme/15/Palette015.spcolor” is the color palette that is already on the site. You can add your own color palettes as well.

  • “MySiteTheme” is the name this generated theme takes on. You can put just about anything here.

  • On the $theme.ApplyTo method, the second parameter indicates whether or not this theme should propagate to each subsite. In this example, it is set to $false.

This script could be applied to sites that you cannot access this setting through the web interface or could even be applied to batches of sites. For instance, you could do a foreach statement to apply this to each SPWeb in a site collection.

Hopefully you find this useful.

Update:

Here is an example of using this to update the theme applied to each users personal site (My Content / SkyDrive):

1 Comment

  1. I got an exception on the line
    $theme.ApplyTo($web, $false)

    Exception calling “ApplyTo” with “2” argument(s): “Unable to cast COM object of type ‘Microsoft.SharePoint.Library.SPRequestInternalClass’ to interface type ‘Microsoft.SharePoint.Library.ISPRequest’. This operation failed because the QueryInterface call on the COM component for the interface with IID ‘{BDEADF28-C265-11D0-BCED-00A0C90AB50F}’ failed due to the following error: Bad variable type. (Exception from HRESULT: 0x80020008 (DISP_E_BADVARTYPE)).”

    I didn’t look into it further as I switched to a different approach as outlined here, http://jespermchristensen.wordpress.com/2013/08/02/changing-the-colors-of-your-sharepoint-2013-or-office-365-my-site/. This worked for me.

    Reply

Submit a Comment

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

Pin It on Pinterest

Share This