It’s possible to add the logo by the user interface, however, if you’ve multiple sites inside the Site Collection, to update the logo will take time to go on each SharePoint subsite and set the logo. On this article and with PNP PowerShell, we’ll share a script that will update the logo on all subsites of the site collection.
The below script will upload the logo for the site collection directly from your desktop to the Site Assets list and them update the logo on the site.
cls
$loginUrl = "https://contoso.sharepoint.com/sites/SITENAME/" #SharePoint site
$username = "contoso@contoso.com"
$password = "password"
$imgPath = "C:\Users\Contoso\Documents\contoso-logo.png"
$encpassword = convertto-securestring -String $password -AsPlainText -Force
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $encpassword
Connect-PnPOnline -Url $loginUrl -Credentials $cred
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 "Upload Logo to SiteAssets"
Write-Host "Updated Logo at:" $loginUrl
$subsites = Get-PnPSubWebs -Recurse
foreach ($site in $subsites){
Connect-PnPOnline -Url $site.url -Credentials $cred
Set-PnPWeb -SiteLogoUrl $pathImg.FileRef
Write-Host "Updated Logo at:" $site.url
}
Write-Host "All Done"
Write-Host "Press any key to Close..."
$Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
Conclusion
All the sites on the Site Collection are now updated with the fresh logo.
Be First to Comment