SharePoint Online: Apply Modern Theme using PowerShell

Requirement: Change the site theme in SharePoint Online

How to apply theme in SharePoint Online?
In SharePoint Online, Themes are responsible for colors in various elements of the site. There are set of default site themes available for selection. You can also add your own custom theme to SharePoint Online. To set a theme in SharePoint Online modern sites,
  • Open your SharePoint Online site where you want to change the theme >> Click on the "Settings" gear icon.
  • In the "Settings" menu, click on "Change the Look"
  • Under themes, Select your desired theme (out of the box or custom theme) and click the "Save" button. The colors on themes can be further customized by clicking on the "Customize" button.
    sharepoint online change theme
  • This changes the theme for the site. Any user with Design or Full Control permission level have the ability to change site themes.

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?

PnP PowerShell to Change Theme in SharePoint Online
Here is how to change theme in SharePoint Online using PowerShell. Make sure you have the theme added prior running this script.
$SiteURL = ""
$ThemeName = "Corporate Theme"

#Connect to Site
Connect-PnPOnline -Url $SiteURL -UseWebLogin

#Apply Theme
Set-PnPWebTheme -Theme "Corporate Theme" -WebUrl $SiteURL

PnP PowerShell to Apply Theme to All Subsites in a Site Collection
#Function to set Theme for a web
Function Set-PnPSiteTheme([Microsoft.SharePoint.Client.Web]$Web, [String]$ThemeName)
    Try {
        Write-host "Applying Theme on site: " $Web.URL
        #Set Theme for the site
        Set-PnPWebTheme -Theme $ThemeName -WebUrl $Web.URL
        #Get All Subsites
        $SubWebs = Get-PnPSubWebs -web $Web
        Foreach ($web in $SubWebs)
            Set-PnPSiteTheme -Web $Web -ThemeName $ThemeName
    catch {
        write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
$SiteURL = ""
$ThemeName= "Corporate Theme"
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential) #-UseWebLogin
#Get the Root Web
$Web = Get-PnPWeb
#Call the function to set site theme
Set-PnPSiteTheme -Web $Web -ThemeName $ThemeName
SharePoint Online: Apply Modern Theme using PowerShell SharePoint Online: Apply Modern Theme using PowerShell Reviewed by Salaudeen Rajack on July 30, 2019 Rating: 5

1 comment:

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


Please Login and comment to get your questions answered!

Powered by Blogger.