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.
cls
$tenantAdmin = "https://Contoso-admin.sharepoint.com"
$hubSite = "https://Contoso.sharepoint.com/sites/ContosoHub"
$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.SiteUrl){
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
try{
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
}
catch{
Write-Host $_.ToString() -BackgroundColor Red
}
}
Write-Host "All Done"
Write-Host "Press any key to Close..."
$Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
PowerShell Result:
Conclusion
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.
References
Apply SPFx extensions to SharePoint Hub Sites using PnP PowerShell (João Ferreira)
[…] Add Logo to Hub Site and all the associated sites automatically – David Ramalho (BindTuning) […]
[…] workflows, although it's not presently recommended for production environments. Also profiled was a PowerShell script that lets organizations associate the same logo across Hub Sites and associated sites. A Web Part […]
This is awesome, though you’re missing a ‘ on Line 10 after ‘GROUP#0
Thanks!
Hi Alex,
Thanks for the note! Already fixed 😊
how to apply spfx extension to the SharePoint Hubsite along with associated sites using spfx?
Hi,
Take a look at the following link that contains a PnP PowerShell script more aligned with what you looking for:
https://sharepoint.handsontek.net/2018/05/13/apply-spfx-extensions-to-sharepoint-hub-sites-using-pnp-powershell/
My best,
David Ramalho