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:>"
    $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!

1 Comment

  • comment-avatar
    Tony June 14, 2019 (12:20 am)

    Thank you!