1

Is it possible to create a script that will loop through all the sites in a site tenancy to replace the logo that is attached to each one. I'm unable to locate any useful commands in the SPO Commandlet set.

2 Answers 2

0

You can use below snippet to set the site logo

$ClientContext.Web.SiteLogoUrl = "http://logourl";
$ClientContext.Web.Update()
$ClientContext.ExecuteQuery()

Below snippet can be used to get all sites

$SecurePassword = ConvertTo-SecureString "PassWord" -AsPlainText -Force 
$Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials("UserName", $SecurePassword) 
$ClientContext = New-Object Microsoft.SharePoint.Client.ClientContext("SiteUrl") 
$ClientContext.Credentials = $Cred

$Web = $ClientContext.Web 
$ClientContext.Load($Web) 
$ClientContext.ExecuteQuery() 

function Get-SPOAllWebs{ 
    Param( 
    [Microsoft.SharePoint.Client.ClientContext]$ClientContext, 
    [Microsoft.SharePoint.Client.Web]$Root 
    ) 

    $Webs = $Root.Webs 
    $ClientContext.Load($Webs) 
    $ClientContext.ExecuteQuery() 

    ForEach ($w in $Webs) 
    { 
        #Logic to update SITELOGO
        Get-SPOAllWebs -RootWeb $w -Context $ClientContext
    } 
}
2
  • Was this taken from a blog? I think I came across something like this when googling. What are the dependencies? Get-SPOAllsites for instance isn't an OOB command as far as I can see but an additional script from TechNet. gallery.technet.microsoft.com/office/… What else would I need to install? Commented Oct 3, 2017 at 12:49
  • You need to recursively query to get all the webs.. hence we need to create a function and call it. The initial source was from a blog which I modified and using it. Commented Oct 3, 2017 at 12:52
0

this one works for me: https://github.com/t1llo/change_logo_SharePointOnline-PS

#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()

full code on https://github.com/t1llo/change_logo_SharePointOnline-PS

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.