Add Logo to Hub Site and all the associated sites automatically

When you create Hub Sites, it’s required to add multiple logos to all the associated sites. With a simple PowerShell Script, we can set all those sites to have the same logo.

With the following PowerShell Script, we will have the same logo applied to Hub and all the associated Hub sites. This PowerShell it’ll also show the sites where the logo cannot be applied because of permissions.

$tenantAdmin = ""
$hubSite = ""
$imgPath = "C:\Users\Contoso\Desktop\__sitelogo__LOGO.jpg"

Connect-PnPOnline -Url $tenantAdmin -UseWebLogin

$HubSite = Get-PnPHubSite $hubSite
$HubSiteId = $HubSite.SiteId
$ModernSites = (Get-PnPTenantSite -Template 'GROUP#0) + (Get-PnPTenantSite -Template 'SITEPAGEPUBLISHING#0') 
$SitesFromHub = New-Object System.Collections.ArrayList

Write-Host ("Searching {0} sites:" -f $HubSite.Title) -BackgroundColor Gray
foreach ($ModernSite in $ModernSites){
  $site = Get-PnPHubSite $ModernSite.Url
   if($site.SiteId -eq $HubSiteId){
    Write-Host ("* {0} - {1}" -f $ModernSite.Title, $ModernSite.Url)
    $SitesFromHub.Add($ModernSite) | Out-Null

Write-Host ""
Write-Host "Upload Logo at:" -BackgroundColor Gray
foreach ($SiteHub in $SitesFromHub){
 Write-Host ("* {0} - {1} ... " -f $SiteHub.Title, $SiteHub.Url) -NoNewline	
 Connect-PnPOnline -Url $SiteHub.Url -UseWebLogin

  New-PnPList -Title "Site Assets" -Template DocumentLibrary  -Url "SiteAssets" -ErrorAction SilentlyContinue
  Add-PnPFile -Path $imgPath -Folder SiteAssets -ErrorAction Stop
  $imgName = $imgPath | Split-Path -Leaf
  $pathImg = (Get-PnPListItem -List SiteAssets -Fields FileRef).FieldValues | Where-Object {$_.FileRef -match $imgName}  
  Set-PnPWeb -SiteLogoUrl $pathImg.FileRef		
  Write-Host "Done" -BackgroundColor Green
  Write-Host $_.ToString() -BackgroundColor Red

Write-Host "All Done"
Write-Host "Press any key to Close..."

PowerShell Result:


After you run this PowerShell, you will have all the associated Hub Sites and Hub Site with the same logo. Note that if you’re facing an issue with the logo not being applied that could be related with the older Office 365 groups. More information on the next link from Microsoft tech community.

On the GIF below, you can check the result of the script.


Apply SPFx extensions to SharePoint Hub Sites using PnP PowerShell (João Ferreira)


Leave a Reply

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