Update Logo using CSOM for SharePoint Online.



How to update the Update Logo using CSOM for SharePoint Online / 0365

The following PowerShell will update SharePoint Online logo for Site Collection /sites/sctest

function UpdateLogo(){

Add-Type -Path "C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell\Microsoft.SharePoint.Client.Runtime.dll"
try{

$siteUrl = "https://spdemo.sharepoint.com/sites/sctest"
$credential = Get-Credential
$Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($credential.UserName,$credential.Password);

$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
[System.Net.WebRequest]::DefaultWebProxy.Credentials = $Creds # needed for default gateway.
$ctx.Credentials = $Creds;
$ctx.Web.SiteLogoUrl = "/SiteAssets/banner.jpg";
$ctx.Web.Update();
$ctx.ExecuteQuery();
$ctx.Dispose();
Set-OutPut "Logo Updated.." "NO ERROR"
$OutMsg = $OutMsg + "QH Logo Updated." + "`r`n"
Write-host $OutMsg
}
catch{
$Outmsg = $OutMsg + "`r`n"
$Outmsg = $OutMsg + "Error in function: UpdateLogo" + "`r`n"
$OutMsg = $OutMsg + "Line : $($_.InvocationInfo.ScriptLineNumber)" + "`r`n"
$OutMsg = $OutMsg + "$($_.Exception)" + "`r`n"
$OutMsg = $OutMsg + "$($_.Exception.Message)" + "`r`n"
Write-host $OutMsg
}

}


No comments:

Post a Comment