Change the color of SharePoint modern experience automatically

SharePoint modern experience is available for Lists, Document Libraries and Pages and while it delivers new functionalities to the end users it lacks some of the customization options available in the classic SharePoint.

The modern experience is provided with a theme that is responsible to format the colors of the elements in the page. On modern site collections like group and communication sites there’s a native interface that allows the administrator to control the color theme, but on classic site collections things are a little bit different and the modern experience will receive a random color applied automatically.

SharePoint Color

I found this article from Karin Skapski that explains in detail how you can manually modify the colors of your sites using the Change the Look functionality and based on this I decided to automate the process using PowerShell.

Requirements

To achieve the steps described in this article you will need to install the SharePoint Color Pallet Tool and the SharePoint PnP PowerShell.

SharePoint Color Pallet Tool provides the color palette functionality to use with SharePoint designs.

SharePoint PnP PowerShell provides a set of commands that allows you to perform complex operations towards SharePoint simplifying the process.

How to change the color of SharePoint modern experience

  1. Open the SharePoint Color Pallet Tool
  2. Click on the color tile next to the Recolor button
  3. Introduce your main color for the theme, it needs to be provided in RGB
  4. Click Recolor, modify the individual color slots as needed
    SharePoint Color Tool
  5. Go to File and Save the color scheme
  6. Copy or download the PowerShell script bellow
    cls
    $themeName = "Yellow"
    
    #URL of the site collection
    $targetSiteCollection = "https://contoso.sharepoint.com/"
    
    #Path of the source folder containing your color file (ends with \)
    $filePath = "C:\path\to\file\"
    
    #File name including extension
    $fileName = "yellow.spcolor"
    
    #Autenticate on SharePoint Online site collection, credentials might be requested
    Connect-PnPOnline -UseWebLogin -Url $targetSiteCollection
    
    #Get the relatative url of the site collection 
    $relativeWebUrl = Get-PnPWeb
    $relativeWebUrl = $relativeWebUrl.ServerRelativeUrl
    
    #Path to the theme gallery
    $targetDir = "/_catalogs/theme/15"
    
    #Upload the theme file to the themes library
    Add-PnPFile -Path ($filePath+$fileName) -Folder $targetDir
    
    #Register the theme on the Composed Looks list
    Add-PnPListItem -List "Composed Looks" -ContentType "Item" -Values @{"Title"=$themeName; "Name"=$themeName; "MasterPageUrl"=$relativeWebUrl+"/_catalogs/masterpage/seattle.master, "+$relativeWebUrl+"/_catalogs/masterpage/seattle.master"; "ThemeUrl"=$relativeWebUrl+"/_catalogs/theme/15/"+$fileName+", "+$relativeWebUrl+"/_catalogs/theme/15/"+$fileName+""; "DisplayOrder"="1"}
    
    #Reset all sites in the site collection to use the uploaded theme
    $pathToColorFile = $relativeWebUrl+"/_catalogs/theme/15/"+$fileName
    write-host "Applying the theme..."
    Set-PnPTheme -ColorPaletteUrl $pathToColorFile -ResetSubwebsToInherit
    
    
  7. Modify the variables $themeName, $targetSiteCollection and $filePath to reflect your values
    The script automates the following tasks:
    • Upload the color file to the Theme library
    • Register the theme on the Composed Looks list
    • Apply the theme to all the sites of the site collection
  8. Execute the script on the PowerShell console e.g. ./ApplyNewColorSiteCollection.ps1
  9. If requested authenticate on SharePoint Online

The process might take a few minutes depending of the number of sites you have in your site collection; the theme will be applied to all the existent sites but unfortunately it will not be applied to sites created after the execution of the script.

Before

SharePoint Modern Sites Default

After

SharePoint Modern Sites Default with color


3 Responses to “Change the color of SharePoint modern experience automatically”

  1. Karin

    December 14, 2017

    Awesome post, glad mine inspired you to take it the next level with a solution that is easily deployable to multiple site collections. I’m sure this script will come in handy for many, thanks for sharing. 🙂

    Reply
  2. Chris

    March 27, 2018

    Access denied. You do not have permission to perform this action or access this resource.

    i receive the following now which sucks as every site is a different bloody colour.

    Reply

Leave a Reply to Chris


I've been working with Microsoft Technologies over the last ten years, mainly focused on creating collaboration and productivity solutions that drive the adoption of Microsoft Modern Workplace.

%d bloggers like this: