Checking HTTP Request/Response in PowerShell

Checking HTTP Request/Response in PowerShell

This is as much for my reference as it may be yours, but here is a quick PowerShell script to check a HTTP request/response.

# Create the request
$HTTP_Request = [System.Net.WebRequest]::Create('http://www.google.com')

# Get the response
$HTTP_Response = $HTTP_Request.GetResponse()

# Get the HTTP as a interger
$HTTP_Status = [int]$HTTP_Response.StatusCode

If ($HTTP_Status -eq 200) {
    Write-Host "Site is OK!"
}
Else {
    Write-Host "The Site may be down, please check!"
}

# Clean up and close the request.
$HTTP_Response.Close()

Thanks for reading and good luck!

Dennis Eugene Stepp, Jr. avatar
About Dennis Eugene Stepp, Jr.
I am a software developer in Knoxville, TN. I'm also a game/web developer with Unibear Studio, and stage manager/web developer with the Earl Park Fall Festival Foundation. My interests include: process and workflow optimization, automation, JAMstack technologies, software architecture, object oriented languages, and game development. I also collect retro PC/console video games, dabble in gardening and woodworking. I have a passion for craft beer, especially while playing recreational ice hockey.