Changing SharePoint Online Modern Site Theme with PowerShell

If you want to change the theme of your site in the SharePoint Online modern site template, you must first develop a theme. You can use the Microsoft’s Theme Generator website for this.

You can access the site via https://developer.microsoft.com/en-us/fluentui#/styles/themegenerator?fabricVer=5

Theme Generator offers you a very simple interface. With this interface, you can quickly create a theme suitable for your main color theme and you can preview what kind of theme you will have with the sample views at the bottom of the page.

Theme Generator will generate 3 different types of output for you.

  • JSON
  • SASS
  • PowerShell

PowerShell output looks like;

@{
"themePrimary" = "#abcdef";
"themeLighterAlt" = "#9ab7d5";
"themeLighter" = "#87a1bb";
"themeLight" = "#748aa1";
"themeTertiary" = "#617386";
"themeSecondary" = "#4e5d6c";
"themeDarkAlt" = "#3b4651";
"themeDark" = "#282f37";
"themeDarker" = "#15191d";
"neutralLighterAlt" = "#f8f8f8";
"neutralLighter" = "#f4f4f4";
"neutralLight" = "#eaeaea";
"neutralQuaternaryAlt" = "#dadada";
"neutralQuaternary" = "#d0d0d0";
"neutralTertiaryAlt" = "#c8c8c8";
"neutralTertiary" = "#c2c2c2";
"neutralSecondary" = "#858585";
"neutralPrimaryAlt" = "#4b4b4b";
"neutralPrimary" = "#333333";
"neutralDark" = "#272727";
"black" = "#1d1d1d";
"white" = "#ffffff";
"primaryBackground" = "#ffffff";
"primaryText" = "#333333";
"bodyBackground" = "#ffffff";
"bodyText" = "#333333";
"disabledBackground" = "#f4f4f4";
"disabledText" = "#c8c8c8";
}

To deploy this theme to your SharePoint Online (actually Microsoft 365) environment, you can use a script like the one below.

Connect-SPOService "https://yourtenantname-admin.sharepoint.com" -Credential (Get-Credential)
$themeName="Custom Theme 1"
$palette = @{
"themePrimary" = "#7b6a56";
"themeLighterAlt" = "#faf8f7";
"themeLighter" = "#eae5df";
"themeLight" = "#d7cec4";
"themeTertiary" = "#afa190";
"themeSecondary" = "#8a7966";
"themeDarkAlt" = "#6e5f4d";
"themeDark" = "#5d5041";
"themeDarker" = "#453b30";
"neutralLighterAlt" = "#f8f8f8";
"neutralLighter" = "#f4f4f4";
"neutralLight" = "#eaeaea";
"neutralQuaternaryAlt" = "#dadada";
"neutralQuaternary" = "#d0d0d0";
"neutralTertiaryAlt" = "#c8c8c8";
"neutralTertiary" = "#c2c2c2";
"neutralSecondary" = "#858585";
"neutralPrimaryAlt" = "#4b4b4b";
"neutralPrimary" = "#333333";
"neutralDark" = "#272727";
"black" = "#1d1d1d";
"white" = "#ffffff";
"primaryBackground" = "#ffffff";
"primaryText" = "#333333";
"bodyBackground" = "#ffffff";
"bodyText" = "#333333";
"disabledBackground" = "#f4f4f4";
"disabledText" = "#c8c8c8";
}

Add-SPOTheme -Name $themeName -Palette $palette -IsInverted:$false -Overwrite

Please note that we use Microsoft Online admin site url during SPOService connection.

Add a Comment

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