Welcome!

Blog Feed Post

How to: Use PowerShell to customize the theme of a SharePoint Modern Site

At Microsoft Ignite, they announced new capabilities for working with themes on modern sites.  Although, the new theme picker they have shown has not rolled out, you can still make use of the new theming capabilities right now.

Here is what the old theme picker looks like.  When we are done, we’ll have our own themes in there and the stock themes will be gone.  No longer will your users pick some awful theme for your sites!

Screen Shot 2017-10-17 at 2.58.01 PM

The easiest way to build your new theme is to go to the Theme Generator page on the Office Fabric site.  Here you can set a color and it will automatically choose a palette for you.  You can override the colors in the palette based upon your own company’s brand standard.  Just pick a Primary theme color or enter in the hex or RGB codes.

Screen Shot 2017-10-17 at 3.04.36 PM

When you scroll down, you will find the code you need, but scroll even further and you will see a preview of what the Fabric Palette looks like.

Screen Shot 2017-10-17 at 3.06.35 PM

Once you are happy, we’ll cut and paste the theme definition into our PowerShell script.  However, before we do that, we have to install the SharePoint Online Management Shell (if you don’t have it already) and connect to SharePoint Online.  You’ll need version 16.0.6906.1200 or newer.  If you haven’t updated in a while, download it again.

One you have it installed, you need to connect to SharePoint Online.  You’ll need to use an account with the SharePoint administrator or Global Administrator roles.  The process involves specifying the URL for your SharePoint Online tenant and the credentials.

$adminUPN="[email protected]"

$orgName="mydomain"

$userCredential = Get-Credential -UserName $adminUPN -Message "Type the password."

Connect-SPOService -Url https://$orgName-admin.sharepoint.com -Credential $userCredential

If you have trouble connecting, you can find more details on Microsoft Docs.  If you use multi-factor authentication, leave off the credential parameter and it will prompt you with an OAuth login prompt.  I’ll usually save this snipped in a PowerShell script so I don’t have to look it up every time.

Now that you are connected, we can add a theme. Create a new PowerShell script using PowerShell ISE, Visual Studio Code, or whatever editor you like.  Add the following to the script.

function HashToDictionary {
   Param ([Hashtable]$ht)
   $dictionary = New-Object "System.Collections.Generic.Dictionary``2[System.String,System.String]"
   foreach ($entry in $ht.GetEnumerator()) {
     $dictionary.Add($entry.Name, $entry.Value)
   }
   return $dictionary
}

$themepallette = HashToDictionary(

)

Add-SPOTheme -Name "New Company Theme" -Palette $themepallette -IsInverted $false -Overwrite

PowerShell expects the theme in the format of a dictionary object.  That is what the helper method HashToDictionary does.  Now we paste in our color palette from the Theme Generator into the call to the HashToDictionary method.  Be sure to incldue the @ symbol.  Here is what the palette looks like on the theme generator.

Screen Shot 2017-10-17 at 3.27.10 PM

Cut and paste that into the script.  The completed script will now look like the following:

function HashToDictionary {
   Param ([Hashtable]$ht)
   $dictionary = New-Object "System.Collections.Generic.Dictionary``2[System.String,System.String]"
   foreach ($entry in $ht.GetEnumerator()) {
     $dictionary.Add($entry.Name, $entry.Value)
   }
   return $dictionary
}

$themepallette = HashToDictionary(
@{
"themePrimary" = "#4ea3e9";
"themeLighterAlt" = "#f6fafe";
"themeLighter" = "#edf6fd";
"themeLight" = "#dbecfa";
"themeTertiary" = "#b4d8f5";
"themeSecondary" = "#5eabea";
"themeDarkAlt" = "#3194e5";
"themeDark" = "#1974bf";
"themeDarker" = "#135b96";
"neutralLighterAlt" = "#f8f8f8";
"neutralLighter" = "#f4f4f4";
"neutralLight" = "#eaeaea";
"neutralQuaternaryAlt" = "#dadada";
"neutralQuaternary" = "#d0d0d0";
"neutralTertiaryAlt" = "#c8c8c8";
"neutralTertiary" = "#b5b5b5";
"neutralSecondary" = "#868686";
"neutralPrimaryAlt" = "#6e6e6e";
"neutralPrimary" = "#252525";
"neutralDark" = "#565656";
"black" = "#3e3e3e";
"white" = "#ffffff";
"primaryBackground" = "#ffffff";
"primaryText" = "#252525";
"bodyBackground" = "#ffffff";
"bodyText" = "#252525";
"disabledBackground" = "#f4f4f4";
"disabledText" = "#c8c8c8";
}
)

Add-SPOTheme -Name "New Company Theme" -Palette $themepallette -IsInverted $false -Overwrite

The Add-SPOTheme Cmdlet has a few parameters.  Name should be fairly self explanatory.  Set IsInverted to true if you are using an inverted theme (ie high contract / black background).  Add the Overwrite to allow you to update the theme after it has been created.  Run the PowerShell script to see your new theme.  Running it will not yield any output if it is successful.

Refresh your SharePoint site and click on Change the Look underneath the Cog Wheel.  You should see your new theme.

Screen Shot 2017-10-17 at 3.32.49 PM

Select the theme to apply it to preview it on your site.

Screen Shot 2017-10-17 at 3.34.41 PM

Pretty simple right?  Now, if you want to remove the out-of-the-box themes.  That’s easy too.  Go back to PowerShell and issue the following command.

Set-HideDefaultThemes $true

Refresh your site and you will see that the out-of-the-box themes are now gone.

Screen Shot 2017-10-17 at 3.37.09 PM

That’s all there is to it.  There are a few more commands if you want to inspect what themes are installed or you want to remove one.  You can read more about them on Microsoft Docs.  Give it a try today!

Read the original blog entry...

More Stories By Corey Roth

Corey Roth, a SharePoint Server MVP, is a consultant at Hitachi Consulting specializing in SharePoint and Office 365 for clients in the energy sector. He has more than ten years of experience delivering solutions in the energy, travel, advertising and consumer electronics verticals.

Corey specializes in delivering ECM and search solutions to clients using SharePoint. Corey has always focused on rapid adoption of new Microsoft technologies including Visual Studio 2013, Office 365, and SharePoint.

He is a member of the .NET Mafia (www.dotnetmafia.com) where he blogs about the latest technology and SharePoint. He is dedicated to the community and speaks regularly at user groups and SharePoint Saturdays.

Latest Stories
Widespread fragmentation is stalling the growth of the IIoT and making it difficult for partners to work together. The number of software platforms, apps, hardware and connectivity standards is creating paralysis among businesses that are afraid of being locked into a solution. EdgeX Foundry is unifying the community around a common IoT edge framework and an ecosystem of interoperable components.
In his session at 21st Cloud Expo, Carl J. Levine, Senior Technical Evangelist for NS1, will objectively discuss how DNS is used to solve Digital Transformation challenges in large SaaS applications, CDNs, AdTech platforms, and other demanding use cases. Carl J. Levine is the Senior Technical Evangelist for NS1. A veteran of the Internet Infrastructure space, he has over a decade of experience with startups, networking protocols and Internet infrastructure, combined with the unique ability to it...
"MobiDev is a software development company and we do complex, custom software development for everybody from entrepreneurs to large enterprises," explained Alan Winters, U.S. Head of Business Development at MobiDev, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
Vulnerability management is vital for large companies that need to secure containers across thousands of hosts, but many struggle to understand how exposed they are when they discover a new high security vulnerability. In his session at 21st Cloud Expo, John Morello, CTO of Twistlock, addressed this pressing concern by introducing the concept of the “Vulnerability Risk Tree API,” which brings all the data together in a simple REST endpoint, allowing companies to easily grasp the severity of the ...
Agile has finally jumped the technology shark, expanding outside the software world. Enterprises are now increasingly adopting Agile practices across their organizations in order to successfully navigate the disruptive waters that threaten to drown them. In our quest for establishing change as a core competency in our organizations, this business-centric notion of Agile is an essential component of Agile Digital Transformation. In the years since the publication of the Agile Manifesto, the conn...
In his session at 21st Cloud Expo, James Henry, Co-CEO/CTO of Calgary Scientific Inc., introduced you to the challenges, solutions and benefits of training AI systems to solve visual problems with an emphasis on improving AIs with continuous training in the field. He explored applications in several industries and discussed technologies that allow the deployment of advanced visualization solutions to the cloud.
Enterprises are adopting Kubernetes to accelerate the development and the delivery of cloud-native applications. However, sharing a Kubernetes cluster between members of the same team can be challenging. And, sharing clusters across multiple teams is even harder. Kubernetes offers several constructs to help implement segmentation and isolation. However, these primitives can be complex to understand and apply. As a result, it’s becoming common for enterprises to end up with several clusters. Thi...
While some developers care passionately about how data centers and clouds are architected, for most, it is only the end result that matters. To the majority of companies, technology exists to solve a business problem, and only delivers value when it is solving that problem. 2017 brings the mainstream adoption of containers for production workloads. In his session at 21st Cloud Expo, Ben McCormack, VP of Operations at Evernote, discussed how data centers of the future will be managed, how the p...
"NetApp is known as a data management leader but we do a lot more than just data management on-prem with the data centers of our customers. We're also big in the hybrid cloud," explained Wes Talbert, Principal Architect at NetApp, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
"Space Monkey by Vivent Smart Home is a product that is a distributed cloud-based edge storage network. Vivent Smart Home, our parent company, is a smart home provider that places a lot of hard drives across homes in North America," explained JT Olds, Director of Engineering, and Brandon Crowfeather, Product Manager, at Vivint Smart Home, in this SYS-CON.tv interview at @ThingsExpo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
The question before companies today is not whether to become intelligent, it’s a question of how and how fast. The key is to adopt and deploy an intelligent application strategy while simultaneously preparing to scale that intelligence. In her session at 21st Cloud Expo, Sangeeta Chakraborty, Chief Customer Officer at Ayasdi, provided a tactical framework to become a truly intelligent enterprise, including how to identify the right applications for AI, how to build a Center of Excellence to oper...
"IBM is really all in on blockchain. We take a look at sort of the history of blockchain ledger technologies. It started out with bitcoin, Ethereum, and IBM evaluated these particular blockchain technologies and found they were anonymous and permissionless and that many companies were looking for permissioned blockchain," stated René Bostic, Technical VP of the IBM Cloud Unit in North America, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Conventi...
"Akvelon is a software development company and we also provide consultancy services to folks who are looking to scale or accelerate their engineering roadmaps," explained Jeremiah Mothersell, Marketing Manager at Akvelon, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
Coca-Cola’s Google powered digital signage system lays the groundwork for a more valuable connection between Coke and its customers. Digital signs pair software with high-resolution displays so that a message can be changed instantly based on what the operator wants to communicate or sell. In their Day 3 Keynote at 21st Cloud Expo, Greg Chambers, Global Group Director, Digital Innovation, Coca-Cola, and Vidya Nagarajan, a Senior Product Manager at Google, discussed how from store operations and ...
"Infoblox does DNS, DHCP and IP address management for not only enterprise networks but cloud networks as well. Customers are looking for a single platform that can extend not only in their private enterprise environment but private cloud, public cloud, tracking all the IP space and everything that is going on in that environment," explained Steve Salo, Principal Systems Engineer at Infoblox, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Conventio...