CSOM PowerShell function to check if the a SharePoint Online site exits? It accepts credential and Url and return true or false.





$siteUrl = 'https://spo.sharepoint.com/sites/teamsite'
$credential = Get-Credential;

function CheckSiteExists($credential,$siteUrl){

 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" 

     $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
     $Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($credential.UserName,$credential.Password);
     [System.Net.WebRequest]::DefaultWebProxy.Credentials = $Creds # needed for default gateway.
     $ctx.Credentials = $Creds;
     $web = $ctx.Web
      $ctx.Load($web)
      try{
            $ctx.ExecuteQuery()         
            return $true
         }
         catch{           
            return $false
        
         }  
        
}

#Calling the function: CheckSiteExits  $credentials $siteUrl

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
}

}