Last active
November 29, 2020 21:01
-
-
Save angelmmg90/75d43bf1d2ac5c56f39b754f2adc23ad to your computer and use it in GitHub Desktop.
A gist for checking web status
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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