You must update the Windows PowerShell to minimum of version 4.0 for the script below to work.
[array]$SiteLinks = "http://mypage.global/Chemical/test.html"
"http://maypage2:9080/portal/site/hotpot/test.json"
foreach($url in $SiteLinks) {
try {
Write-host "Verifying $url" -ForegroundColor Yellow
$checkConnection = Invoke-WebRequest -Uri $url
if ($checkConnection.StatusCode -eq 200) {
Write-Host "Connection Verified!" -ForegroundColor Green
}
}
catch [System.Net.WebException] {
$exceptionMessage = $Error[0].Exception
if ($exceptionMessage -match "503") {
Write-Host "Server Unavaiable" -ForegroundColor Red
}
elseif ($exceptionMessage -match "404") {
Write-Host "Page Not found" -ForegroundColor Red
}
}
}