Add a custom theme to SharePoint using PowerShell

11 July 2023

SharePoint provides users with a default set of themes which can be used to change the colours of sites. There are a good selection of default themes, but if your organization has got a specific colour scheme you may want to create a custom theme in line with your brand. We’re going to create a new theme and add it to SharePoint so that it’s available across all our sites.

Generate the new theme

We firstly need to generate this new theme. Fortunately, there is an online theme generator which allows you to input your colours and then generates the code for you.

Choose your primary, text and background colours and then export your theme in the PowerShell format.

Connecting to SharePoint from PowerShell

Once you have the code for your theme we can add it to SharePoint. To do this you will need an account that has access to the SharePoint admin center.

We’ll connect to the admin center by providing the Connect-SPOService cmdlet with the url of your admin center. Executing this line in PowerShell will bring up a dialogue box requiring you to sign in with a SharePoint administrator account.

PowerShell
Connect-SPOService -url "https://ben-admin.sharepoint.com"

Adding a new theme

To add the custom theme to SharePoint we use the Add-SPOTheme cmdlet. But before we do that, and to make this easier to read visually, we’ll assign the theme code we exported from the online theme generator to a variable in PowerShell.

PowerShell
$themepalatte = @{
"themePrimary" = "#0078d4";
"themeLighterAlt" = "#eff6fc";
"themeLighter" = "#deecf9";
"themeLight" = "#c7e0f4";
"themeTertiary" = "#71afe5";
"themeSecondary" = "#2b88d8";
"themeDarkAlt" = "#106ebe";
"themeDark" = "#005a9e";
"themeDarker" = "#004578";
"neutralLighterAlt" = "#faf9f8";
"neutralLighter" = "#f3f2f1";
"neutralLight" = "#edebe9";
"neutralQuaternaryAlt" = "#e1dfdd";
"neutralQuaternary" = "#d0d0d0";
"neutralTertiaryAlt" = "#c8c6c4";
"neutralTertiary" = "#a19f9d";
"neutralSecondary" = "#605e5c";
"neutralSecondaryAlt" = "#8a8886";
"neutralPrimaryAlt" = "#3b3a39";
"neutralPrimary" = "#323130";
"neutralDark" = "#201f1e";
"black" = "#000000";
"white" = "#ffffff";
}

We can now run the Add-SPOTheme cmdlet to add our new theme to SharePoint. This cmdlet will take a few parameters:

-Identity specifies a unique name for our new theme.

-Palette the theme code from the online generator.

-IsInverted specifies whether the theme has a dark background.

-Overwrite overwrites the theme in SharePoint if a theme with that name exists already.

PowerShell
Add-SPOTheme -Identity "Bens theme" -Palette $themepalette -IsInverted 0 -Overwrite

The theme is now available on SharePoint and can be applied through the Change the look menu.

Hiding default themes

You may want to hide the default Microsoft themes so that people setting up SharePoint sites only have the option to choose from themes that you provide. To do this there is a cmdlet called Set-SPOHideDefaultThemes which takes a boolean parameter of 0 or 1.

I’m going to hide the default themes by entering the following into PowerShell.

PowerShell
Set-SPOHideDefaultThemes 1

If I change my mind at any time, I can show the default themes again by simply running the same command but replacing the 1 with a 0.

You can read the full Microsoft docs detailing the use of the Add-SPOTheme cmdlet.