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.
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
Leave a Reply
You must be logged in to post a comment.
16 replies on “Changing site logo for all sub sites in a Site collection for SharePoint Online (Office 365)”
Excellent Adnan
I constantly emailed this weblog post page to all my contacts, because if like to
read it then my friends will too.
Thanks alot, I really appropriate for spreading the word to the community.
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!
I have used blogengine.net 10 years back, I think there must be some plugin which can import all blog posts for you.
I need to to thank you for this good read!! I absolutely loved every bit of it.
I have you book marked to check out new stuff you post…
Thanks alot for motivating me, I really appropriate.
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!
yes sure, please share your details at adnan.amin@hotmail.com, I will really like to have more bloggers at MSTechTalk.
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!!
Thanks, please share the issue which you are getting in RSS, I will try to resolve it asap. check this url if you are getting any issues https://mstechtalk.com/feed/
My brother recommended I would possibly like this blog.
He used to be totally right. This putt up truly mawde my
day. You can noot believe simply how so much time I had spent for
this info! Thank you!
Thankyou so much 🙂
What’s up, just wanted to tell you, I enjoyed this blog
post. It was practical. Keep on posting!
Hmm is anyone else having problems with the images on this blog loading?
I’m trying to figure out if its a problem on my end
or if it’s the blog. Any feedback would be greatly appreciated.
Mapping Office Attributes to OneLogin Attributes.