Skip to content

Commit

Permalink
Create Update-SharePoint-SiteLogos.ps1
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewbadge authored Aug 29, 2021
1 parent dd115c2 commit cd9541e
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions Office365-Sharepoint/Update-SharePoint-SiteLogos.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<#
.SYNOPSIS
Update the root site and subsites to the logo specified
.DESCRIPTION
Creds supplied will need to be a site wonerr for all sites
.INPUTS
[String] $SiteUrl (Root site to Process)
[String] $LogoURL (Logo Path to Set)
.NOTES
File Name : Update-SharePointSiteLogos.ps1
Author : Andrew Badge
Prerequisite : Powershell 5.1
Thanks and Reference: https://www.sharepointdiary.com/2016/11/sharepoint-online-how-to-change-logo-using-powershell.html
#>

#Add PowerShell Module for SharePoint Online
Import-Module Microsoft.Online.SharePoint.Powershell -DisableNameChecking

##Configuration variables. Change these to suit
$SiteUrl = "https://orgname.sharepoint.com/sites/sitename"
$LogoURL="/sites/sitename/Style Library/Logos/Logo.png"

$Cred = Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)


Try {

#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)
{
try {
#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)
}
}
Catch {
write-host -f Red "Error updating Logo for " $Web.URL $_.Exception.Message
}
}

#Call the function to change the logo of the web
Update-Logo($Web)
}
Catch {
write-host -f Red "Error updating Logo!" $_.Exception.Message
}

0 comments on commit cd9541e

Please sign in to comment.