$currentDir = [System.IO.Path]::GetDirectoryName($myInvocation.MyCommand.Definition); [System.Reflection.Assembly]::LoadFrom("$($currentDir)\bin\Microsoft.SharePoint.Client.dll")|Out-Null 2>&1 [System.Reflection.Assembly]::LoadFrom("$($currentDir)\bin\Microsoft.SharePoint.Client.Runtime.dll")|Out-Null 2>&1 function CheckSpConnection { param( [string]$webUrl, [string]$expectedTitle, [string]$desc ) try { Write-Host -ForegroundColor Yellow "Testing '$($desc)': $($webUrl)" $context = new-object Microsoft.SharePoint.Client.ClientContext($webUrl) # $context.Credentials = New-Object System.Net.NetworkCredential("madziap","xxxxxx","domgen") $w = $context.Web; $context.Load($w) $context.ExecuteQuery(); if($expectedTitle -eq $w.Title){ Write-Host -NoNewline -ForegroundColor Green "OK: " Write-Host -ForegroundColor White "The connection to server '$($webUrl)' was successfull" } else { Write-Host -NoNewline -ForegroundColor Red "ERR: " Write-Host -ForegroundColor White "The connection to server was successfull but the site title is invalid, expected '$($expectedTitle)', got '$($w.Title)'" } } catch { $ex = $_.Exception Write-Host -NoNewline -ForegroundColor Red "ERR: " Write-Host -ForegroundColor White $ex.Message } } CheckSpConnection "http://localhost/xxx" "XXX Title" "XXX SITE TEST DESC" CheckSpConnection "http://localhost/yyy" "YYY Title" "YYY SITE TEST DESC"