Skip to content

Instantly share code, notes, and snippets.

@SoulOfUniverse
Created July 13, 2021 19:01
Show Gist options
  • Save SoulOfUniverse/169f714cd1456ee7c3e0e995d28a0f5f to your computer and use it in GitHub Desktop.
Save SoulOfUniverse/169f714cd1456ee7c3e0e995d28a0f5f to your computer and use it in GitHub Desktop.
Pinging any target url
# First we create the request.
$HTTP_Request = [System.Net.WebRequest]::Create('https://google.com')
$HTTP_Request.Timeout = 60000
# 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 up! OK!" -ForegroundColor Cyan
}
Else {
Write-Error "The Site may be down, please check!"
}
# Finally, we clean up the http request by closing it.
If ($HTTP_Response -eq $null) { }
Else { $HTTP_Response.Close() }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment