Thursday, December 21, 2017

How to check if a web by its' url is up and running by Powershell

function IsTheWebUrlUp { try { Invoke-WebRequest -Uri $webUrlLocation -UseBasicParsing ` -UseDefaultCredential | Select-Object StatusDescription ` | Tee-Object -Variable isWebUp | Out-Null; return $isWebUp.StatusDescription -eq "OK" } Catch { write-host "Caught an exception:" -ForegroundColor Red write-host "Exception Type: $($_.Exception.GetType().FullName)" -ForegroundColor Red write-host "Exception Message: $($_.Exception.Message)" -ForegroundColor Red return $false; } }

Share/Bookmark