SharePoint Online: How to Change Site Logo using PowerShell?

Changing logo is a common requirement when it comes to branding SharePoint online sites.

How to change Logo in SharePoint Online:
Changing logo in SharePoint online is a matter of few clicks. To add 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).
    SharePoint Online PowerShell Change Logo
  • 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 How to Change Site Logo using PowerShell
As soon as you upload an image for the logo, You'll find the new logo reflected immediately on the top left-hand side of the site. Optionally, you can enter a description of the logo. This description becomes a tooltip for your new logo. Click on the "OK" button to save your changes. Click cancel to discard.

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!

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

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.
Make sure you have added yourself as a site collection administrator to all sites in the tenant prior to executing this script! How to add a site collection administrator to all SharePoint Online sites in the tenant?
#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
}

5 comments:

  1. Hi Salaudeen,

    How to change site collection URL in SharePoint online?

    Thanks.

    ReplyDelete
    Replies
    1. 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.

      Delete
  2. This comment has been removed by the author.

    ReplyDelete
  3. PS C:\WINDOWS\system32> Set-SPOSiteLogo -Web $Web -LogoURL $LogoURL
    Set-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

    ReplyDelete
  4. How to redirect the logo "click URL" to redirect to the root site collection?

    ReplyDelete

Please Login and comment to get your questions answered!

Powered by Blogger.