SharePoint Online: How to Change Site Logo using PowerShell?
How to change Logo in SharePoint Online?
Changing the logo is a common requirement when it comes to branding SharePoint Online sites and it can be achieved in few clicks. To add a logo to SharePoint Online, follow these steps:
- Log in as a Site Administrator to your SharePoint Online site. Click on Settings gear >> Select Site Settings >> In the Site settings page, click on "Title, description, and logo" link (/_layouts/15/prjsetng.aspx).
- That takes you to a page where you can set a Logo for the site. You can use either a logo from your computer or any existing logo from your SharePoint site (Even any existing image from the Internet too).
- Click on "From Computer" link >> Browse and upload your logo file. Once you upload, the logo file gets saved into "Site Assets" Library of the site.
SharePoint Online PowerShell to Change Logo:
Changing the logo from web UI is fairly simple, isn't it? Well, what if you have a site collection with hundreds of sub-sites and sub-sub-sites? What if different versions of your company logo used by different sites and you want to make them consistent? PowerShell is the answer! Let's use PowerShell script to change the site logo in SharePoint online.
#Add PowerShell Module for SharePoint Online Import-Module Microsoft.Online.SharePoint.Powershell -DisableNameChecking ##Configuration variables $SiteUrl = "https://crescent.sharepoint.com/" $LogoURL="/SiteAssets/Logo.png" #Existing file Try { #Get Credentials to connect $Cred = Get-Credential $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password) #Setup the context $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl) $Ctx.Credentials = $Credentials $Web = $Ctx.Web #Change Logo $Web.SiteLogoUrl = $LogoURL $Web.Update() $Ctx.ExecuteQuery() Write-host "Logo Updated Successfully!" -ForegroundColor Green } Catch { write-host -f Red "Error updating Logo!" $_.Exception.Message }Please note, the file URL at LogoURL must be an existing file in SharePoint online site. So, upload the logo to the root of your site collection first.
PowerShell to Change the site logo for a site collection and its subsites:
Let's change the logo for all sites within a SharePoint Online site collection. Make sure you have uploaded the "logo.png" file in the site assets library prior to executing this script.
#Add PowerShell Module for SharePoint Online Import-Module Microsoft.Online.SharePoint.Powershell -DisableNameChecking ##Configuration variables $SiteUrl = "https://crescent.sharepoint.com/Sites/Sales" $LogoURL="/SiteAssets/Logo.png" Try { #Get Credentials to connect $Cred = Get-Credential $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password) #Setup the context $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl) $Ctx.Credentials = $Credentials #Get the Root web $Web = $Ctx.Web $Ctx.Load($Web) $Ctx.ExecuteQuery() #Function to change Logo for the given web Function Update-Logo($Web) { #Update Logo $Web.SiteLogoUrl = $LogoURL $Web.Update() $Ctx.ExecuteQuery() Write-host "Updated Logo for Web:" $Web.URL #Process each subsite in the site $Subsites = $Web.Webs $Ctx.Load($Subsites) $Ctx.ExecuteQuery() Foreach ($SubSite in $Subsites) { #Call the function Recursively Update-Logo($Subsite) } } #Call the function to change the logo of the web Update-Logo($Web) } Catch { write-host -f Red "Error updating Logo!" $_.Exception.Message }
PnP PowerShell to Change Logo for All Sites in a SharePoint Online Site Collection
This time, let's set the logo on each web in the site collection. Instead of referring the logo from the top-level web, let's upload it to each site and then use PnP PowerShell to change the site logo in SharePoint Online.
#Function to set site Logo Function Set-PnPSiteLogo { [cmdletbinding()] param( [parameter(Mandatory = $true, ValueFromPipeline = $false)]$Web, [parameter(Mandatory = $true, ValueFromPipeline = $false)][String] $LogoFilePath ) Try { Write-host "Updating Logo on Site '$($Web.URL)'" #Ensure "Site Assets" library in the site $SiteAssets = Get-PnPList -Web $Web -Identity "Site Assets" -ErrorAction SilentlyContinue If($SiteAssets -eq $Null) { New-PnPList -Web $Web -Title "Site Assets" -Template DocumentLibrary -Url "SiteAssets" -ErrorAction SilentlyContinue | Out-Null } #Upload Logo File to 'Site Assets' library of the current web Add-PnPFile -Web $Web -Path $LogoFilePath -Folder "SiteAssets" | Out-Null #Get File Name from Logo File's Full Path $LogoFileName = Split-Path $LogoFilePath -leaf #Set Site Logo Set-PnpWeb -Web $Web -SiteLogoUrl "$($Web.ServerRelativeUrl)/SiteAssets/$($LogoFileName)" #Get All Subwebs $SubWebs = Get-PnPSubWebs -web $Web Foreach ($web in $SubWebs) { #Call the function recursively Set-PnPSiteLogo -Web $Web -LogoFilePath $LogoFilePath } } catch { write-host "Error: $($_.Exception.Message)" -foregroundcolor Red } } #Parameters $SiteURL = "https://crescent.sharepoint.com/sites/Marketing" $LogoPath = "C:\Temp\Logo.jpg" #Connect to Site Connect-PnPOnline -Url $SiteURL -UseWebLogin $Web = Get-PnPWeb #Call the function to change site logo Set-PnPSiteLogo -Web $Web -LogoFilePath $LogoPath
However, this PowerShell works only for non-group connected sites!
SharePoint Online: How to Change Logo in Modern Sites
Unlike classic sites, changing the site logo for a Modern team sites and communication sites is really simpler.
- Navigate to the Site >> Click on Settings gear >> Click on "Site Information" Link.
- This opens the site information panel, where you can click on "Change" button to browse any supported image as logo for the site. Once the After the image is uploaded, you see the preview of the image.
- Click Save to commit your changes.
How to Change Logo on Modern Group Connected Sites?
If the site is created in Office 365 Groups or Teams, Then the logo changed in those apps doesn't reflect back to SharePoint Online. Simply replace the file "__siteIcon__.jpg" under "Site Assets" library (create one if it doesn't exist!) to change the site logo!
If you want to set the site logo for Modern group connected sites with PowerShell, use Set-PnPSite cmdlet with "LogoFilePath" Parameter:
$SiteURL = "https://crescent.sharepoint.com/sites/Purchase" $LogoPath = "C:\Temp\Logo.jpg" #Connect to Site Connect-PnPOnline -Url $SiteURL -UseWebLogin #Set Site Logo Set-PnPSite -LogoFilePath $LogoPath
In group connected sites, when trying to change the site logo, I got an error message: "We experienced a problem updating the icon. Please try again in a few minutes." This is because: The user who tried changing the site logo was not the Group owner! Just add the user as Office 365 Group Owner, and he should be able to change the site logo!
How to change the site logo in the entire tenant for all sites and subsites?
This PowerShell script iterates through each site collection in the tenant and updates the Logo from the parameters. This script can handle both classic sites and modern group connected sites.
#Parameters $Domain = "Crescent" #Your Domain Name in SharePoint Online. E.g. https://Crescent.SharePoint.com $LogoFilePath = "C:\Temp\SPLogo.jpg" $Cred = Get-Credential #Frame Tenant URL and Tenant Admin URL $TenantURL = "https://$Domain.SharePoint.com" $TenantAdminURL = "https://$Domain-Admin.SharePoint.com" #Function to set site Logo Function Set-PnPSiteLogo { [cmdletbinding()] param( [parameter(Mandatory = $true, ValueFromPipeline = $True)]$Web, [parameter(Mandatory = $true, ValueFromPipeline = $False)][String] $LogoFilePath ) Try { #Ensure "Site Assets" library in the site $SiteAssets = Get-PnPList -Web $Web -Identity "Site Assets" -ErrorAction SilentlyContinue If($SiteAssets -eq $Null) { New-PnPList -Web $Web -Title "Site Assets" -Template DocumentLibrary -Url "SiteAssets" -ErrorAction SilentlyContinue | Out-Null } #Upload Logo File to 'Site Assets' library of the current web Add-PnPFile -Web $Web -Path $LogoFilePath -Folder "SiteAssets" | Out-Null #Get File Name from Logo File's Full Path $LogoFileName = Split-Path $LogoFilePath -leaf #Set Site Logo Set-PnpWeb -Web $Web -SiteLogoUrl "$($Web.ServerRelativeUrl)/SiteAssets/$($LogoFileName)" Write-host "`n`tUpdated Logo on Web '$($Web.URL)'" -f Green #Get All Subwebs $SubWebs = Get-PnPSubWebs -web $Web Foreach ($web in $SubWebs) { #Call the function recursively Set-PnPSiteLogo -Web $Web -LogoFilePath $LogoFilePath } } catch { write-host "Error: $($_.Exception.Message)" -foregroundcolor Red } } #Connect to Admin Center Connect-PnPOnline -Url $TenantAdminURL -Credentials $Cred #Get All Site collections - Exclude BOT, Video Portals and MySites $Sites = Get-PnPTenantSite -Filter "Url -like $TenantURL -and Url -notlike '-my.sharepoint.com/' -and Url -notlike '/portals/'" #Iterate through all site collections $Sites | ForEach-Object { #Connect to each site collection $SiteConn = Connect-PnPOnline -Url $_.URL -Credentials $Cred -ReturnConnection Write-host "Processing Site Collection:"$_.URL -f Yellow -NoNewline #Check if its a Group site If($_.Template -like 'GROUP*') { Set-PnPSite -LogoFilePath $LogoFilePath Write-host "`n`tUpdated Logo on Group Site!" -f Green } Else { #Call the Function for site & all Subwebs Get-PnPWeb -Connection $SiteConn | Set-PnPSiteLogo -LogoFilePath $LogoFilePath } Disconnect-PnPOnline -Connection $SiteConn }
Hi Salaudeen,
ReplyDeleteHow to change site collection URL in SharePoint online?
Thanks.
Unfortunately, its not possible to rename site collection URL's in SharePoint Online as of Today! The only alternate is to create a new site collection and copy content over.
DeleteThis comment has been removed by the author.
ReplyDeletePS C:\WINDOWS\system32> Set-SPOSiteLogo -Web $Web -LogoURL $LogoURL
ReplyDeleteSet-SPOSiteLogo : No se puede procesar la transformación del argumento del parámetro 'Web'. No se puede convertir el
valor "Microsoft.SharePoint.Client.Web" de tipo "Microsoft.SharePoint.Client.Web" al tipo
"Microsoft.SharePoint.Client.Web".
En lÃnea: 1 Carácter: 22
+ Set-SPOSiteLogo -Web $Web -LogoURL $LogoURL
+ ~~~~
+ CategoryInfo : InvalidData: (:) [Set-SPOSiteLogo], ParameterBindingArgumentTransformationException
+ FullyQualifiedErrorId : ParameterArgumentTransformationError,Set-SPOSiteLogo
How to redirect the logo "click URL" to redirect to the root site collection?
ReplyDeletePositive site, where did u come up with the information on this posting?I have read a few of the articles on your website now, and I really like your style. Thanks a million and please keep up the effective work. Logo design Dallas
ReplyDelete