In our recent project we get requirements to modify Header layout and Site logo of SharePoint modern site.
Recently, modern site header layout customization options are released in SharePoint Online/O365. With these options you can customized header layout and change the site logo.
From the “Change the look” option under site setting you can find the options to change the Header Layout and Site Logo.
Header customization options.
There are two layout options available: Standard and Compact.
STANDARD HEADER
COMPACT HEADER
Site logo allows uploading of a new logo and removing a logo. If you want to reuse your logo from another site, you need to update logo URL via code.
For header background, there are four options from left to right: None, Neutral, Soft and Strong.
Header background options
Modifying header with PnP PowerShell
In our recent SharePoint migration project, we have a requirement to migrate Header layout and Site logo in large number of sites.
As our requirement was to update more than 10000 sites it is difficult to modify Header layout and Site logo from UI.
Header layout options can be easily modified with just few lines of PnP PowerShell.
We create a script that read site details from a comma separated csv file and update the Header layout and Site logo of the specified sites.
Follow the below steps to modify Header layout and Site logo –
Prerequisite
Before you begin utilizing PowerShell to oversee SharePoint Online, ensure that the SharePoint Online Management Shell is installed. You can install the SharePoint Online Management Shell by downloading and running the SharePoint Online Management Shell. You only need to do this once for each computer from which you are running SharePoint Online PowerShell commands
Step1: Run PowerShell as Administrator
Step 2: Install PnP PowerShell latest module
Install-Module SharePointPnPPowerShellOnline -Force
Step 3: To Modify Header Layout and Site logo run the below script
#Install-Module SharePointPnPPowerShellOnline -force
#Set the source csv file path
$SourceCSVFilePath="D:\SiteDetails.csv";
################# Set the SharePoint Site User Id and Password ###############
$SPUserId = "DemoUser@*****.onmicrosoft.com"
$SPUserPassword="*******";
$EncryptPassword = convertto-securestring -String $SPUserPassword -AsPlainText -Force
$Credential = new-object -typename System.Management.Automation.PSCredential -argumentlist $SPUserId, $EncryptPassword
try
{
$SiteDetails = Import-CSV -path $SourceCSVFilePath -Header("SiteUrl","LogoUrl")
}
catch [System.Exception]
{
Write-Host -ForegroundColor Red $_.Exception.ToString()
break;
}
Write-Host -ForegroundColor Green "Processing data from CSV file."
$RowCount=0
foreach ($row in $SiteDetails)
{
############ skip the column header in csv file
if($RowCount -eq 0)
{
$RowCount=$RowCount+1
}
else
{
try
{
if($row.SiteUrl -ne "")
{
######## Connecting To SP Site ###############################
$webUrl=$row.SiteUrl;
$LogoUrl=$row.LogoUrl;
Write-Output $("Connecting to {0}..." -f $webUrl);
Connect-PnPOnline -Url $webUrl -Credentials $Credential
Write-Host -ForegroundColor Yellow "Site Connected...."
########## Update Header Layout and Site Logo ################
$web = Get-PnPWeb -Includes HeaderEmphasis,HeaderLayout,SiteLogoUrl
$web.HeaderLayout = "Compact" # Options: Standard, Compact
$web.HeaderEmphasis = "Strong" # Options None, Neutral, Soft, Strong
$web.SiteLogoUrl = $LogoUrl # Set the site Logo
$web.Update()
Invoke-PnPQuery
Write-Host ($RowCount) "] Header Layout and Site Logo Updated...."
$RowCount=$RowCount+1;
}
}
catch [System.Exception]
{
Write-Host -ForegroundColor Red $_.Exception.ToString()
}
}
}
Source csv file format
After applying “Compact” Header Layout and Site logo
Conclusion
So, there you go, this is how we can update Header layout and Site logo in Modern SharePoint Sites using PnP PowerShell