SharePoint Online: Apply Modern Theme using PowerShell

Requirement: Change the site theme in SharePoint Online.

How to apply a theme in SharePoint Online?

In Microsoft SharePoint Online, Themes are responsible for colors in various site elements. Themes can create a consistent look and feel across multiple sites. To align with your organization’s branding guidelines, you can create and apply a theme in SharePoint Online. There is a set of default site themes available for selection. You can also add your custom theme to SharePoint Online. How do I change the theme in SharePoint Online? To set a theme in SharePoint Online modern sites, follow these steps:

I’m assuming you have your custom theme deployed using Add-SPOTheme cmdlet in SharePoint Online Management Shell, refer to: How to Add a Custom Theme SharePoint Online using PowerShell?

  1. Open your SharePoint Online site where you want to change the theme, as SharePoint Admin >> Click on the “Settings” gear icon.
  2. In the “Settings” menu, click on “Change the Look”.
  3. Under themes, you’ll see a variety of pre-built themes that you can use. You can preview the theme by selecting the desired theme (out of the box or custom theme).
  4. When you’re happy with how it looks, click the “Save” button to make it live on your site. The colors on themes can be further customized by clicking on the “Customize” button.
    sharepoint online change theme
  5. This changes the theme of the site. Any user with a Design or Full Control permission level has the ability to change site themes.

Once you have selected the new theme, it will be applied to your site immediately. You can always go back and change the theme later if you want to try something different.

SharePoint Online allows custom themes, which can be easily created and applied using PowerShell, providing more flexibility and control over the appearance of your SharePoint sites. Here is my other post on adding a modern theme using PowerShell in SharePoint Online: How to Add a Modern Theme using PowerShell in SharePoint Online?

Apply a Theme using PowerShell

Here is the PowerShell script to apply a theme to a SharePoint Online site:

#Connect to Admin Center
Connect-SPOService -Url "https://crescent-admin.sharepoint.com"

#Set the Theme for the site
Set-SPOWebTheme -Theme "Crescent Green" -Web https://crescent.sharepoint.com/sites/Retail

The theme “Crescent Green” is a custom theme deployed in my environment.

PnP PowerShell to Change Theme in SharePoint Online

Here is how to change the theme in SharePoint Online using PowerShell. Make sure you have the theme added before running this script.

#Parameters
$AdminCenterURL = "https://crescent-admin.sharepoint.com"
$SiteURL = "https://crescent.sharepoint.com/sites/marketing"
$ThemeName = "Crescent Theme"
 
#Connect to Admin Center
Connect-PnPOnline -Url $AdminCenterURL -Interactive
 
#Apply Theme to Web
Set-PnPWebTheme -Theme $ThemeName -WebUrl $SiteURL

PnP PowerShell to Apply Theme to All Subsites in a Site Collection

You can change the look and feel of a SharePoint site to match your corporate color scheme through themes.

#Function to set Theme for a web
Function Set-PnPSiteTheme($Web, [String]$ThemeName)
{
    Try {
        Write-host "Applying Theme on site: " $Web.URL
        Connect-PnPOnline -Url $Web.URL -Interactive
  
        #Set Theme for the web
        Set-PnPWebTheme -Theme $ThemeName
    }
    catch {
        write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
    }
}
  
#Parameters
$AdminCenterURL = "https://Crescent-admin.sharepoint.com"
$SiteURL = "https://Crescent.sharepoint.com/sites/marketing"
$ThemeName= "Crescent Theme"
   
#Connect to Admin Center
$AdminConn = Connect-PnPOnline -Url $AdminCenterURL -Interactive -ReturnConnection
 
#Connect to SharePoint Online Site
$SiteConn = Connect-PnPOnline -Url $SiteURL -Interactive -ReturnConnection

#Get all the Webs - Exclude App Sites
$Webs = Get-PnPSubWeb -Recurse -IncludeRootWeb -Connection $SiteConn | Where {$_.WebTemplate -ne "App"}

#Call the function to set site theme for site collection
$Webs | ForEach-Object { Set-PnPSiteTheme -Web $_ -ThemeName $ThemeName }

How to Apply a Default theme in SharePoint Online using PowerShell?

Alright, Instead of a custom theme, If you want to apply an out-of-the-box default theme to your SharePoint Online sites, here is the PowerShell script:

#Config Variables
$SiteURL = "https://crescent.sharepoint.com/sites/intranet"
  
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive
$Web = Get-PnPWeb 

#Apply OOTB Modern Theme
[OfficeDevPnP.Core.Utilities.Themes.ThemeManager]::ApplyTheme($Web, [OfficeDevPnP.Core.Enums.SharePointTheme]::Blue)

Here is the enumeration of available default themes:

powershell to change sharepoint online site theme

To apply a composite that includes a color theme, font, and background URL in Classic SharePoint Online, use: SharePoint Online: How to Change Site Theme using PowerShell?

Wrapping up

In conclusion, applying a theme in SharePoint Online is a powerful way to customize the look and feel of your SharePoint sites. By utilizing the SharePoint Online CSOM PowerShell or the Set-PnPWebTheme cmdlet of PnP PowerShell, administrators can easily apply a theme to one or multiple sites with just a few lines of code. This can save a significant amount of time and effort compared to applying themes manually. With the power of PowerShell, applying themes to your SharePoint Online sites has never been easier.

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

9 thoughts on “SharePoint Online: Apply Modern Theme using PowerShell

  • In 2024, the PnP to set to a default theme has changed.

    This is no longer accurate.
    [OfficeDevPnP.Core.Utilities.Themes.ThemeManager]::ApplyTheme($Web, [OfficeDevPnP.Core.Enums.SharePointTheme]::Blue)

    Use the PNP Framework type references instead
    [PnP.Framework.Utilities.Themes.ThemeManager]::ApplyTheme($Web, [PnP.Framework.Enums.SharePointTheme]::Blue)

    Thank you

    Reply
  • Is there a way to apply a custom theme to all active sites in the tenant via powershell? Not subsites but all /sites/* addresses.

    Reply
  • Hi wondering if you would recommend doing this before creation of site collections on a tenant? If I apply the PowerShell script to a current tenant I see reactions where some of the web parts text is no longer visible due to the background color. Seems like if this is applied to a large tenant that there would be a lot of rework to do.

    Reply
  • This article saved me a lot of time. God bless you, Salaudeen.

    Reply
  • Set-PnPSiteTheme function does not work and throw a 401 error.
    Is there a workaround for that ?
    With Connect-PnPOnline as -admin the $web will be admin site…
    Help please

    Reply
  • pnpPowershell to set theme doesn’t work.
    need to set Connect-PnPOnline url as -admin, not the site url you are applying theme to.

    Reply
    • Yes, We need Tenant Admin Rights to run “Set-PnPWebTheme” cmdlet and must connect to Tenant Admin!

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *