Managing SharePoint Online Themes with PowerShell

Managing SharePoint Online Themes with PowerShell

🎯 Introduction

The visual appearance of SharePoint sites plays a key role in user experience and corporate identity...

βœ… Prerequisites

  1. SharePoint Online Management Shell is installed
  2. Administrator rights for SharePoint Online
  3. Windows PowerShell 5.x
  4. Admin URL: https://<your-tenant-name>-admin.sharepoint.com

🎨 Create a Custom Theme

Use the Fluent UI Theme Designer: https://aka.ms/themedesigner

  1. # ⚠️ This script must be executed in Windows PowerShell 5.x with administrator privileges!
  2. # Recommended: Windows PowerShell 5.x (not PowerShell 7)

  3. # -----------------------------------------
  4. # Step 0: Install SharePoint Online Management Shell (if not already installed)
  5. # Note: Only run this if the module is not installed yet
  6. # -----------------------------------------
  7. if (-not (Get-Module -ListAvailable -Name Microsoft.Online.SharePoint.PowerShell)) {
  8.     Write-Host "Installing SharePoint Online Management Shell..." -ForegroundColor Cyan
  9.     Install-Module -Name Microsoft.Online.SharePoint.PowerShell -Scope CurrentUser -Force
  10. }

  11. Import-Module Microsoft.Online.SharePoint.PowerShell -ErrorAction Stop
  12. Write-Host "SharePoint Online PowerShell module loaded." -ForegroundColor Green

  13. # -----------------------------------------
  14. # Step 1: Connect to the SharePoint Admin Center
  15. # -----------------------------------------
  16. $adminUrl = "https://<your-tenant-name>-admin.sharepoint.com"
  17. Write-Host "Connecting to: $adminUrl" -ForegroundColor Cyan
  18. Connect-SPOService -Url $adminUrl

  19. # -----------------------------------------
  20. # Step 2: Define the theme
  21. # -----------------------------------------
  22. $themeName = "Teamsware Purple"

  23. $palette = @{
  24.     "themePrimary" = "#6667AB";
  25.     "themeLighterAlt" = "#f8f8fc";
  26.     "themeLighter" = "#e2e2f2";
  27.     "themeLight" = "#cacbe6";
  28.     "themeTertiary" = "#9b9ccd";
  29.     "themeSecondary" = "#7576b5";
  30.     "themeDarkAlt" = "#5c5d9a";
  31.     "themeDark" = "#4e4f82";
  32.     "themeDarker" = "#393a60";
  33.     "neutralLighterAlt" = "#faf9f8";
  34.     "neutralLighter" = "#f3f2f1";
  35.     "neutralLight" = "#edebe9";
  36.     "neutralQuaternaryAlt" = "#e1dfdd";
  37.     "neutralQuaternary" = "#d0d0d0";
  38.     "neutralTertiaryAlt" = "#c8c6c4";
  39.     "neutralTertiary" = "#a19f9d";
  40.     "neutralSecondary" = "#605e5c";
  41.     "neutralSecondaryAlt" = "#8a8886";
  42.     "neutralPrimaryAlt" = "#3b3a39";
  43.     "neutralPrimary" = "#323130";
  44.     "neutralDark" = "#201f1e";
  45.     "black" = "#000000";
  46.     "white" = "#ffffff"
  47. }

  48. # -----------------------------------------
  49. # Step 3: Remove existing theme (optional)
  50. # -----------------------------------------
  51. Write-Host "Checking if the theme already exists..." -ForegroundColor Cyan
  52. try {
  53.     Remove-SPOTheme -Name $themeName -ErrorAction Stop
  54.     Write-Host "Existing theme '$themeName' has been removed." -ForegroundColor Yellow
  55. }
  56. catch {
  57.     Write-Host "No existing theme named '$themeName' found. Continuing..." -ForegroundColor Gray
  58. }

  59. # -----------------------------------------
  60. # Step 4: Add the new theme
  61. # -----------------------------------------
  62. try {
  63.     Add-SPOTheme -Name $themeName -Palette $palette -IsInverted:$false -ErrorAction Stop
  64.     Write-Host "βœ” Theme '$themeName' successfully registered tenant-wide." -ForegroundColor Green
  65. }
  66. catch {
  67.     Write-Host "❌ Error adding the theme: $($_.Exception.Message)" -ForegroundColor Red
  68. }

πŸ—‘οΈ Delete a Single Theme

  1. $adminUrl = "https://<your-tenant-name>-admin.sharepoint.com"
    Connect-SPOService -Url $adminUrl

    $themeName = "Teamsware Purple"
    Remove-SPOTheme -Name $themeName

🧹 Delete All Themes

  1. $adminUrl = "https://<your-tenant-name>-admin.sharepoint.com"
    Connect-SPOService -Url $adminUrl

    $themes = Get-SPOTheme
    foreach ($theme in $themes) {
    Remove-SPOTheme -Name $theme.Name
    }


⚠️ Limitations of Add-SPOTheme

Only 32 color slots are supported
Advanced semantic slots like
buttonBackground
are derived automatically

🧩 Using Theme Tokens in SPFx

  1. .button {
  2. background-color: "[theme: buttonBackground, default: #f3f2f1]";
  3. color: "[theme: buttonText, default: #323130]";
  4. }

πŸ”§ Tools & Resources

πŸ“₯ Install SharePoint Online Management Shell

  1. Open PowerShell as Administrator
  2. Check if module is installed:
    Get-Module -ListAvailable -Name Microsoft.Online.SharePoint.PowerShell
  3. Install module:
    Install-Module -Name Microsoft.Online.SharePoint.PowerShell -Scope CurrentUser -Force
  4. Import module (optional):
    Import-Module Microsoft.Online.SharePoint.PowerShell

πŸ“Œ Disclaimer

Note: The information and scripts provided in this article have been created with great care. However, Teamsware GmbH assumes no liability for the accuracy, completeness, or timeliness of the content. Use of the provided information is at your own risk. Please test all scripts in a suitable test environment before using them in production.

    • Related Articles

    • The path length limit in SharePoint Online – What you need to know!

      Whether it’s issues with syncing to OneDrive, during governance workshops, or directly from users – the question about path length in SharePoint Online keeps coming up: ? β€œHow is the path length calculated?” ? β€œWhat’s the maximum limit?” No wonder ...
    • How to add Emojis to the name of a Microsoft Teams Channels

      Microsoft has implemented a way to further customize channel names in Microsoft Teams by adding images to the name in the form of emoji icons. At first glance, this may seem like a distraction and a waste of time. But there are good reasons for using ...