How to Check if Site exists in SharePoint Online/ Office 365 using CSOM?

Hello SharePointers,

Below is the CSOM code to check  if site exists in SharePoint Online/ Office 365.

function CheckifSiteExists()

{ param( [Parameter(Mandatory=$true)][string]$siteurl  )

  begin{

$context = New-Object Microsoft.SharePoint.Client.ClientContext($siteurl)

$web = $context.Web

$context.Load($web)

try {    $context.ExecuteQuery()

        return $true        }

  catch {

return $false        }    }

end{

$context.Dispose()

}}

Happy SharePointing Folks 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *