Add a custom theme to SharePoint using PowerShell
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.
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.
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.
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.
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.