Apply Theme and Create Composed Look CSOM and PowerShell

There are several ways a theme can be applied to a SharePoint site.

I tried the PnP command  SetSPOTheme  as follows on SharePoint 2013 On Premises instance.

Set-SPOTheme -ColorPaletteUrl $PathThemeColor -FontSchemeUrl  $PathThemeFont

Unfortunately I was getting message ‘Field or property “AlternateCssUrl” does not exist.’ SetSPOThemeError_AlternateCssUrlDoesNotExist

The error is due not having latest patch installed. Unfortunately the latest SharePoint CU can’t be installed as we have heavily customised legacy applications migrated from SharePoint 2007 and SharePoint 2010 running in compatibility mode.

The other option was to use the add-in “DeployCustomTheme” from PnP samples. However it meant deploying the add-in before applying the theme and add-in catalog has not been enabled on the SharePoint farm.

Using PnP PowerShell Commands the custom theme and master page files can be uploaded to folder “/_catalogs/theme/15” and “/_catalogs/masterpage” respectively.

Deploy Custom Color

Add-SPOFile -Path ".\Files\Themes\Palette_EDRMS.spcolor" -Folder "/_catalogs/theme/15"

Deploy Custom Font

Add-SPOFile -Path ".\Files\Themes\fontscheme_EDRMS.spfont" -Folder "/_catalogs/theme/15"

Deploy Custom Master Page html and preview

Add-SPOFile -Path ".\Files\Themes\MasterPage\seattle_edrms.html" -Folder "/_catalogs/masterpage"


Add-SPOFile -Path ".\Files\Themes\MasterPage\seattle_edrms.preview" -Folder "/_catalogs/masterpage"

After deploying the files, the custom theme can be applied using the PowerShell script below. The custom composed look is created before the theme is applied using the CSOM method “ApplyTheme”

$web.ApplyTheme($themeUrl, $FontSchemeUrl,$BckImageUrl,$true)

After running script, the theme on the site is updated.

AfterRunningCSOMScript.PNG

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s