Applying a SharePoint Online theme to a site collection via PowerShell

Share the love

Applying themes to SharePoint sites is nothing new. However, the way we apply themes to SharePoint sites in SharePoint Online has changed. Themes are an important part of company branding, so it’s often one of the first changes we, or the Marketing department, want to change.

First we need to decide on what colors we want for our theme. Microsoft have showcased how they use their colors with Theme Slots. If you have a primary color, but are stuck for other colors to generate, you can use Microsoft’s Theme Generator Tool which will work out the color combinations based on your primary color, text color and background color.

Once you have your colors, you can write your PowerShell code. Simply change the HEX values of the colors in the code below with your own colors you generated from the Theme Slots.

Connect-SPOService -Url https://mytenant-admin.sharepoint.com/
 
$themepalette = @{
"themePrimary" = "#3395cf";
"themeLighterAlt" = "#f5fafd";
"themeLighter" = "#daecf7";
"themeLight" = "#baddf0";
"themeTertiary" = "#7cbde2";
"themeSecondary" = "#48a1d4";
"themeDarkAlt" = "#2e87ba";
"themeDark" = "#27729d";
"themeDarker" = "#1d5474";
"neutralLighterAlt" = "#f8f8f8";
"neutralLighter" = "#f4f4f4";
"neutralLight" = "#eaeaea";
"neutralQuaternaryAlt" = "#dadada";
"neutralQuaternary" = "#d0d0d0";
"neutralTertiaryAlt" = "#c8c8c8";
"neutralTertiary" = "#b9bec9";
"neutralSecondary" = "#7c8392";
"neutralPrimaryAlt" = "#4a5160";
"neutralPrimary" = "#363c49";
"neutralDark" = "#2a2e38";
"black" = "#1f2229";
"white" = "#ffffff";
}
 
Add-SPOTheme -Identity "My Theme" -Palette $themepalette -IsInverted $false

Special thanks to Laura Kokkarinen who has identified other colors that you can add to your PowerShell script above if you want ultimate control of your colors. These colors have either been omitted from Microsoft’s Theme Generator or were never included. I have added them to my code below for reference.

# No longer included in theme generator
"primaryBackground" = "#FFF7D7";
"primaryText" = "#72BD54";
"bodyBackground" = "#ffbf40";
"bodyText" = "#593c00";
"disabledBackground" = "#CD9D7C";
"disabledText" = "#52834C";

# Never been included in theme generator
"backgroundOverlay" = "#102542";
"whiteTranslucent40" = "rgba(255,255,255,.4)";
"accent" = "#f87060";

If you want to update your theme, it’s as simple as putting the -Overwrite flag on an existing theme. If you’ve forgotten what you called your existing theme, you can get the themes you have deployed via a PowerShell command (make sure you have connected to the SPOService first).

Get-SPOTheme

Once you have the name of your theme, deploy your theme again with the -Overwrite flag.

Connect-SPOService -Url https://mytenant-admin.sharepoint.com/
 
$themepalette = @{
[Theme colors here]
}

Add-SPOTheme -Identity "My Theme" -Palette $themepalette -IsInverted $false -Overwrite

If you would like to remove a theme, simply run this PowerShell command.

Remove-SPOTheme -name "My Theme"

If you want the theme to automatically install on a site, you will need to execute a site design (which I’ll write about in a later post). With the approach described in this post, you will have to manually set the theme on the site the same way you would change a theme normally. On a modern SharePoint site, click the cog on the upper right hand corner and go to Change the look. From here, choose Theme. Your deployed theme should be in the list to choose from.


Share the love

Leave a Reply

Your email address will not be published.