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. To align with your organization branding guidelines, you can create and apply a theme in SharePoint Online. 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,
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 prior to running this script.
PnP PowerShell to Apply Theme to All Subsites in a Site Collection
You can change the look and feel of a SharePoint Online site to match your corporate color scheme through themes.
How to Apply an OOTB Modern Theme in SharePoint Online using PowerShell
Alright, Instead of a custom theme, If you want to apply an out of the box default themes to your SharePoint Online sites, here is the script:
To apply a composite that includes a color theme, font, and background URL in SharePoint Online, use: SharePoint Online: How to Change Site Theme using PowerShell?
How to apply theme in SharePoint Online?
In SharePoint Online, Themes are responsible for colors in various elements of the site. To align with your organization branding guidelines, you can create and apply a theme in SharePoint Online. 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.
- This changes the theme for the site. Any user with a Design or Full Control permission level have the ability to change site themes.
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 prior to running this script.
#Parameters $AdminCenterURL = "https://crescent-admin.sharepoint.com" $SiteURL = "https://creescent.sharepoint.com/sites/marketing" $ThemeName = "Crescent Theme" #Connect to Admin Center Connect-PnPOnline -Url $AdminCenterURL -UseWebLogin #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 Online 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 #Set Theme for the site Set-PnPWebTheme -Theme $ThemeName -Web $Web -Connection $AdminConn #Get All Subsites $SubWebs = Get-PnPSubWebs -web $Web -Connection $SiteConn Foreach ($Web in $SubWebs) { #Call the function recursively Set-PnPSiteTheme -Web $Web -ThemeName $ThemeName } } catch { write-host "Error: $($_.Exception.Message)" -foregroundcolor Red } } #Parameters $AdminCenterURL = "https://crescent-admin.sharepoint.com" $SiteURL = "https://crescent.sharepoint.com/sites/marketing" $ThemeName= "Corporate Theme" #Connect to Admin Center $AdminConn = Connect-PnPOnline -Url $AdminCenterURL -UseWebLogin -ReturnConnection #Connect to SharePoint Online Site $SiteConn = Connect-PnPOnline -Url $SiteURL -UseWebLogin -ReturnConnection #Get the Root Web $Web = Get-PnPWeb -Connection $SiteConn #Call the function to set site theme for site collection Set-PnPSiteTheme -Web $Web -ThemeName $ThemeName
How to Apply an OOTB Modern Theme in SharePoint Online using PowerShell
Alright, Instead of a custom theme, If you want to apply an out of the box default themes to your SharePoint Online sites, here is the script:
#Config Variables $SiteURL = "https://crescent.sharepoint.com/sites/intranet" #Connect to PnP Online Connect-PnPOnline -Url $SiteURL -UseWebLogin $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 themes:
To apply a composite that includes a color theme, font, and background URL in SharePoint Online, use: SharePoint Online: How to Change Site Theme using PowerShell?
pnpPowershell to set theme doesn't work.
ReplyDeleteneed to set Connect-PnPOnline url as -admin, not the site url you are applying theme to.
Yes, We need Tenant Admin Rights to run "Set-PnPWebTheme" cmdlet and must connect to Tenant Admin!
DeleteSet-PnPSiteTheme function does not work and throw a 401 error.
ReplyDeleteIs there a workaround for that ?
With Connect-PnPOnline as -admin the $web will be admin site...
Help please
Script has been updated! Try now.
DeleteIt works!! Thanks a lot
DeleteThis article saved me a lot of time. God bless you, Salaudeen.
ReplyDelete