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('')

# 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.

Thanks for reading and good luck!

Dennis Eugene Stepp, Jr. avatar
About Dennis Eugene Stepp, Jr.
I passionately deliver innovative software solutions that enhance the customer experience and maximize business value. Building upon over eight years of software engineering experience I assist technologists in architecture, automation, design, implementation, testing, and workflow. I continuously broaden my skills through game development, conference speaking, and networking within the software development community.