Branding SharePoint Online sites is crucial for providing a consistent look and feel across an organization. PnP PowerShell allows administrators to automate branding tasks such as applying themes, logos, headers, navigation, and site designs. This guide covers step-by-step automation of SharePoint Online site branding using PnP PowerShell.
1. Connecting to SharePoint Online
Before applying branding settings, establish a secure connection.
Using Modern Authentication (MFA)
Connect-PnPOnline -Url "https://yourtenant.sharepoint.com/sites/YourSite" -UseWebLogin
Using App Registration for Automation
$TenantID = "xxxx-xxxx-xxxx"
$ClientID = "yyyy-yyyy-yyyy"
$CertPath = "C:\Certificates\PnPCert.pfx"
Connect-PnPOnline -Url "https://yourtenant.sharepoint.com" -ClientId $ClientID -Tenant $TenantID -CertificatePath $CertPath
Why? Ensures secure, automated access.
2. Applying a Custom Theme
Retrieve Available Themes
Get-PnPTenantTheme
Apply a Built-in Theme
Set-PnPWebTheme -Theme "Blue" -WebUrl "https://yourtenant.sharepoint.com/sites/YourSite"
Apply a Custom Theme
1️⃣ Define the Theme JSON
$ThemeJson = @"
{
"palette": {
"themePrimary": "#0078d4",
"themeLighterAlt": "#eff6fc",
"themeLighter": "#deecf9",
"themeLight": "#c7e0f4",
"themeTertiary": "#71afe5",
"themeSecondary": "#2b88d8",
"themeDarkAlt": "#106ebe",
"themeDark": "#005a9e",
"themeDarker": "#004578"
}
}
"@
2️⃣ Add the Custom Theme
Add-PnPTenantTheme -Identity "CustomCompanyTheme" -PaletteJson $ThemeJson -IsInverted $false -Overwrite
3️⃣ Apply the Custom Theme
Set-PnPWebTheme -Theme "CustomCompanyTheme" -WebUrl "https://yourtenant.sharepoint.com/sites/YourSite"
Why? Enhances corporate branding consistency.
3. Updating the Site Logo
Set a Site Logo
Set-PnPWeb -SiteLogoUrl "https://yourtenant.sharepoint.com/SiteAssets/logo.png"
Why? Reinforces brand identity across SharePoint sites.
4. Configuring the Header Layout
Apply a Minimal Header
Set-PnPWeb -HeaderLayout Minimal
Apply a Standard Header
Set-PnPWeb -HeaderLayout Standard
Why? Improves site navigation and user experience.
5. Customizing Site Navigation
Add a Navigation Link
Add-PnPNavigationNode -Title "Company Portal" -Url "https://company.com" -Location "TopNavigationBar" -External
Remove a Navigation Link
Remove-PnPNavigationNode -Identity "Company Portal" -Location "TopNavigationBar"
Why? Ensures streamlined navigation across the organization.
6. Automating Branding for Multiple Sites
Apply Branding Across Multiple Sites
$Sites = @(
"https://yourtenant.sharepoint.com/sites/Site1",
"https://yourtenant.sharepoint.com/sites/Site2",
"https://yourtenant.sharepoint.com/sites/Site3"
)
foreach ($site in $Sites) {
Connect-PnPOnline -Url $site -UseWebLogin
Set-PnPWebTheme -Theme "CustomCompanyTheme" -WebUrl $site
Set-PnPWeb -SiteLogoUrl "https://yourtenant.sharepoint.com/SiteAssets/logo.png"
Write-Host "Branding applied to $site"
}
Why? Saves time by applying branding changes in bulk.
7. Using Site Designs and Site Scripts for Branding
Site designs and scripts help enforce consistent branding when new sites are created.
Create a Site Script
$SiteScript = @"
{
"$schema": "schema.json",
"actions": [
{
"verb": "applyTheme",
"themeName": "CustomCompanyTheme"
},
{
"verb": "setSiteLogo",
"url": "https://yourtenant.sharepoint.com/SiteAssets/logo.png"
}
],
"version": 1
}
"@
Add the Site Script
$SiteScriptId = Add-PnPSiteScript -Title "Company Branding Script" -Content $SiteScript
Create a Site Design
Add-PnPSiteDesign -Title "Company Branding Design" -WebTemplate "64" -SiteScripts $SiteScriptId -Description "Applies company branding."
Why? Automatically applies branding when new sites are created.
8. Best Practices for Automating Site Branding
Use Secure Authentication
🔹 Always use MFA or App Registration for secure access.
Maintain Theme Consistency
🔹 Store themes centrally and apply them using automation.
Use Site Designs for Standardization
🔹 Apply pre-configured site designs to new SharePoint sites.
Test in a Development Environment
🔹 Deploy branding updates in test sites first before rolling out company-wide.
Use Logging for Tracking Changes
🔹 Keep a record of branding updates using PowerShell transcripts.
Start-Transcript -Path "C:\Logs\BrandingLog.txt" -Append
Why? Ensures accountability and compliance.