Add a theme to a Modern SharePoint site using Powershell

If you are like me, I am not a Powershell wizard by any stretch of the imagination, so trying to learn how to deploy a modern theme wasn’t exactly the most exciting time. I hope the example below will help those other Power-User/Admin extraordinaires be able to move towards the new world one script at a time.

  1. Download the SharePoint Online Management Shell

    Make sure to download the latest version of SharePoint Online Management Shell    If you haven’t updated it in a while, uninstall the version you have and do a fresh reinstall.

  2. Logging in to your tenant

    Of all things, you would think just logging in would be the easy part, not. If you follow the directions provided by Microsoft, as I did, you will receive a lovely error.
    Microsoft recommends using the following code to log-in:

    $adminUPN="<the full email address of a SharePoint administrator account, example: [email protected]>"
    $orgName="<name of your Office 365 organization, example: contosotoycompany>"
    $userCredential = Get-Credential -UserName $adminUPN -Message "Type the password."
    Connect-SPOService -Url https://$ -Credential $userCredential

    I found that this will error out. My fix is to do the following:

    Connect-SPOService -url https://<your tenant>

    This will bring up the log-in screen for your tenant and voila, you’re in.

  3. Create your theme using the new theme generator

    Microsoft has created a new theme generator for us to use. Open the theme generator.

  4. Input your Hex Color into the generator and press “Enter” to generate the new palette.
  5. Copy the Powershell code into a text editor like Visual Studio Code or Sublime.
  6. To define the new name for the color palette add the following command after the closing brace of the color codes:
    Add-SPOTheme -Name "<your theme name>" -Palette $themepallette -IsInverted $false

    Change out the <your theme name> with what you would like your name to be. Remember to remove the <>.

  7.  Your final script should look like:
    $themepallette = @{
    "themePrimary" = "#1b619d";
    "themeLighterAlt" = "#ecf4fc";
    "themeLighter" = "#cde3f6";
    "themeLight" = "#86bbea";
    "themeTertiary" = "#2e8bdc";
    "themeSecondary" = "#1d68aa";
    "themeDarkAlt" = "#18578e";
    "themeDark" = "#113e65";
    "themeDarker" = "#0f3557";
    "neutralLighterAlt" = "#f8f8f8";
    "neutralLighter" = "#f4f4f4";
    "neutralLight" = "#eaeaea";
    "neutralQuaternaryAlt" = "#dadada";
    "neutralQuaternary" = "#d0d0d0";
    "neutralTertiaryAlt" = "#c8c8c8";
    "neutralTertiary" = "#a6a6a6";
    "neutralSecondary" = "#666666";
    "neutralPrimaryAlt" = "#3c3c3c";
    "neutralPrimary" = "#333333";
    "neutralDark" = "#212121";
    "black" = "#1c1c1c";
    "white" = "#ffffff";
    "primaryBackground" = "#ffffff";
    "primaryText" = "#333333";
    "bodyBackground" = "#ffffff";
    "bodyText" = "#333333";
    "disabledBackground" = "#f4f4f4";
    "disabledText" = "#c8c8c8";
    Add-SPOTheme -Name "<your theme name>" -Palette $themepallette -IsInverted $false
  8. Run the script in Powershell command prompt

    Copy and paste the script into the SharePoint Online Management Shell window and press “Enter” to run.

  9. Choosing the theme on your site

    Navigate to your site and select the “Site Actions” menu or “gear icon” and select “Change the look”.

    You will now see your custom theme option available to you through the selections.

    Select your custom theme and enjoy.

    Your theme has now been applied to your site. Enjoy!

Join the Conversation

  1. Thank you!

  2. Hi,
    May I know how to apply this in on-premise SharePoint 2019? Is it achievable?

    1. D'arce Hess Author says:

      Absolutely. I will write up a post and send it over for you.

      1. hello, if you ever wrote this for sharepoint 2019 on-premise could you please send it to me

      2. Hello,

        Thanks for the post, How to apply custom theme to Modern sites in SP 2019 ?

  3. Is there a way to apply the new theme out to all the existing SPO sites?

    1. D'arce Hess Author says:

      You could apply it using Powershell after a site is created. If you want to have it applied at the time of provisioning, you can use a site design with custom theming applied.

  4. Don’t forget to disconnect with “Disconnect-SPOService”

  5. Thanks so much it worked a treat!!

  6. hi,
    at first i would like to thank you for your contribution.
    I’m looking for the powershell command to change the police tipology by default in sharepoint.

  7. How to add a theme to a modern SharePoint site?
    Adds a theme to the whole tenant

    1. D'arce Hess Author says:

      The themes are stored at a tenant level, there is not way to scope the theme to just a site collection catalogue

  8. Perfect solution! Thank you very much.

  9. Hi all,

    I got an error like this one
    Add-SPOTheme : Cannot bind argument to parameter ‘Palette’ because it is null.
    Any idea why ?

    1. D'arce Hess Author says:

      In order to apply a theme you have to declare the variable $themepalette with the JSON schema first and then run the Add-SPOTheme cmd that calls the $themepalette variable.

  10. Hi, can you please send to me how to do this for on-prem as well?

Comments are closed.

Scroll to top