Changing site logo for all sub sites in a Site collection for SharePoint Online (Office 365)

In my previous article, I shared details for changing site logo for a site collection and its sub sites using PowerShell, but that was only for on-premise environment. PowerShell script for SharePoint Online is different from on-premise where we refer SharePoint client dlls, make sure you should have installed SharePoint Online Management Shell, if not then you can download it from this link.

I have update the script at technet gellery for changing site logo for both SharePoint On-Premise as well as for SharePoint Online, you can download it from this link.

MsTechtalk Technet gallery

Below is the PowerShell script which update the site logo for all sub sites under a site collection, it will ask you for site URL, user name and password.

[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint.Client”)
[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint.Client.Runtime”)

$siteUrl = Read-Host -Prompt “Enter site collection URL (https://mstechalk.sharepoint.com)” #you can also set the site URL
$userToLogin = Read-Host -Prompt “Enter Username” #you can also set the user name, make sure it should be global admin
$password = Read-Host -Prompt “Enter Password” -AsSecureString
$sitelogoURL = “/SiteAssets/newSitelogo.gif” #change the site logo
$clientContext = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($userToLogin, $password)

$clientContext.Credentials = $credentials

$web = $clientContext.get_web()
$webs = $clientContext.Web.Webs;
$clientContext.Load($webs)
$clientContext.Load($web)

$clientContext.ExecuteQuery()

function updateSubSites($subWeb) {
$subsites = $subWeb.Webs;
$clientContext.Load($subsites)
$clientContext.ExecuteQuery()
foreach ($subSite in $subsites) {
updateSiteLogo($subWeb)
updateSubSites($subSite)
}
}

function updateSiteLogo($subWeb) {
$subWeb.SiteLogoUrl = $sitelogoURL
$subWeb.Update();
$clientContext.ExecuteQuery()

Write-Host “Updated logo for ” $subWeb.Title ” , site url:” $subWeb.Url
}

updateSiteLogo($web)

foreach ($subWeb in $webs)
{
write-host “inside bottom foreach”
updateSiteLogo($subWeb)
updateSubSites($subWeb)
}

You might get below exception if the user is not global admin, so make sure you have credentials for global admin.

Exception calling “ExecuteQuery” with “0” argument(s): “The Login server cannot issue the requested compact encrypted ticket because a Data Encryption Key (DEK) has not been uploaded to the site.”

At line:19 char:1

+ $clientContext.ExecuteQuery()

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

    + FullyQualifiedErrorId : IdcrlException

The following two tabs change content below.
Adnan Amin
Adnan is two time SharePoint MVP (Most Valuable Professional) with over 12 years of extensive experience with major expertise on SharePoint Server, Office 365, .Net Platform and Microsoft BI. He is currently working SharePoint Architect at FMT Consultants. He is MCT Regional Lead for Pakistan Chapter since 2012. He is working on SharePoint for past nine years and worked on different intranet/intranet solutions for private & govt. sector majorly in Gulf region, which include OOB and customized solutions. He is a trainer, technology evangelist and also speaks in community forums.

16 Comments

  1. My developer is trying to convince me to move to .net from PHP.
    I have always disliked the idea because of the expenses.
    But he’s tryiong none the less. I’ve been using Movable-type on a variety of websites for about a year and
    am anxious about switching to another platform. I have heard great things about
    blogengine.net. Is there a way I can import all my wordpress content into it?
    Any help would be greatly appreciated!

  2. Please let me know if you’re looking for a writer
    for your site. You have some really good articles and I
    think I would be a good asset. If you ever want to take some
    of the load off, I’d really like to write some material for your blog
    in exchange for a link back to mine. Please shoot me an e-mail
    if interested. Thank you!

  3. Oh my goodness! Incredible article dude! Thank you so much, However I
    am encountering problems with your RSS. I don’t know the reason why I can’t join it.
    Is there anybody having the same RSS problems?
    Anyone who knows the answer can you kindly respond?
    Thanks!!

Leave a Reply

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