Skip to content

Instantly share code, notes, and snippets.

@angelmmg90
Last active November 29, 2020 21:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save angelmmg90/75d43bf1d2ac5c56f39b754f2adc23ad to your computer and use it in GitHub Desktop.
Save angelmmg90/75d43bf1d2ac5c56f39b754f2adc23ad to your computer and use it in GitHub Desktop.
A gist for checking web status
function checkStatusPages([string]$url){
# First we create the request.
$HTTP_Request = [System.Net.WebRequest]::Create($url)
# We then get a response from the site.
$HTTP_Response = $HTTP_Request.GetResponse()
# We then get the HTTP code as an integer.
$HTTP_Status = [int]$HTTP_Response.StatusCode
If ($HTTP_Status -eq 200) {
Write-Host "Site is OK! " $url
}
Else {
Write-Host "The Site may be down, please check! "$url
}
# Finally, we clean up the http request by closing it.
If ($HTTP_Response -eq $null) { }
Else { $HTTP_Response.Close() }
}
$urlToCheck = @(
'http://www.google.com',
'http://www.facebook.com',
'http://pepitolospalotes.cal'
)
For ($i=0; $i -le $urlToCheck.count-1; $i++) {
checkStatusPages($urlToCheck[$i])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment