---
title: "Build Your Own HTTP Monitor with PowerShell"
description: "Ensure your web service's uptime with a custom HTTP monitor. A beginner-friendly guide to coding in PowerShell."
canonical: "https://adamtheautomator.com/http-monitor/"
---

# Build Your Own HTTP Monitor with PowerShell

> Ensure your web service's uptime with a custom HTTP monitor. A beginner-friendly guide to coding in PowerShell.

Source: https://adamtheautomator.com/http-monitor/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![Build Your Own HTTP Monitor with PowerShell](https://adamtheautomator.com/wp-content/uploads/2019/07/5d238ae5c824b514689ea627.jpg)

# Build Your Own HTTP Monitor with PowerShell

[![](https://secure.gravatar.com/avatar/d0b9d42e21e5622713f8b693aa5c0f9244d5f7dd200ed29b8398f52dee5de337?s=192&d=mm&r=g)Adam Bertram](https://adamtheautomator.com/author/adam-bertram/)1 July 20192 min. read

Categories: [IT Ops](/category/it-ops/)

Tags:[PowerShell](/tag/powershell/)

Table of Contents

*   [Building the HTTP Monitor](#command-line-script)
*   [Making the Request](#making-the-request)
*   [Assigning an Integer](#assigning-an-integer)

How would you define a web server as being “up”? It doesn’t just respond to a simple Internet Control Message Protocol (ICMP) echo request (ping) but more importantly, an HTTP monitor is showing as down. That’s where a PowerShell script comes in.

When [monitoring systems](https://www.ipswitch.com/application-and-network-monitoring), it’s important to track as close to the real service as possible. In a web server’s case, that service is an HTTP request.

A web request consists of lots of interdependent parts, including things like the server being connected to the network, having a MAC address, an IP address, a TCP port that’s listening on port 80, and, at the top of this stack, the HTTP status code that the server returns. It’s important to monitor as close to the service as possible, so let’s focus on the HTTP status code.

## Building the HTTP Monitor

There are numerous ways to monitor the status code returned by a web server. We’ll focus on rolling command-line script, which is an excellent way to incrementally build upon certain functionality.

To create these scripts, I always use PowerShell. It’s a great scripting language and the de facto standard in the Windows world.

Because PowerShell doesn’t natively have a command that can get the [HTTP status code from a web server](https://www.whatsupgold.com/blog), we’ll need to take a standard approach and use a .NET object. And since a PowerShell script is ultimately built on top of the .NET framework, this is a trivial task.

To start off, we’ll need to use the System.Net.WebRequest object. In particular, you’ll need to call a static method called Create and pass the URL to this to build the request.

```powershell
$req = [system.Net.WebRequest]::Create('http://www.google.com')
```

> _You also use PowerShell’s Invoke-WebRequest for this task. Check out the [in-depth post here](https://adamtheautomator.com/invoke-webrequest/) on the ATA blog for more info._

## Making the Request

You can see above that I’m creating a web request for google.com. If you look at the request, you’ll see many common properties that will be used to make the request.

But the code doesn’t have much yet. It’s not actually an HTTP monitor just yet. I still need to make the actual request to Google’s web server and get the response. To do this, I’ll need to use the `GetResponse()` method. This makes the request and returns the response from the web server.

```powershell
$res = $req.GetResponse()
```

You can see now that all of the information returned. Notice that the `$res` object has a `StatusCode` property – this is what we’re looking for. At this point, we can either leave this as is and use this code in a larger script, or individually pull out the `StatusCode` by referring to it in dot notation.

```powershell
$res.StatusCode
```

## Assigning an Integer

This will return “OK,” but there’s no such thing as an “OK” HTTP status code. They’re unique integers. To get the actual HTTP status code for the HTTP monitor script, we’ll need to cast this property to an integer. This will return the actual HTTP status code.

```powershell
[int]$res.StatusCode
```

Notice now we can get the real HTTP status code, which is 200.

PowerShell is a powerful scripting language that does a lot more than most sysadmins are aware of. And even if PowerShell doesn’t natively support a task, chances are it can still be done through native .NET objects.

Once you begin to create more code like this, you’ll inevitably find that this kind of code can be treated as building blocks. Continue learning small snippets of code like this, and you’ll have a large bag of script tricks that can be applied in numerous situations.

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fhttp-monitor%2F&text=Build%20Your%20Own%20HTTP%20Monitor%20with%20PowerShell)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fhttp-monitor%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fhttp-monitor%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2026/06/26995-troubleshoot-dns-issues-powershell-codex.webp)

### [Troubleshoot DNS Issues with PowerShell](/troubleshoot-dns-issues-powershell/)

Troubleshoot DNS issues with PowerShell by testing name resolution, DNS client settings, cache entries, and network connectivity in a repeatable workflow.

![](https://adamtheautomator.com/wp-content/uploads/2025/10/image_2025-10-24_095322075.png)

### [Migrating from PowerShell 6 to 7.5: Breaking Changes/New Features](/migrating-powershell-6-to-7-5/)

Migrate from PowerShell Core 6 to 7.5: breaking changes, features, and testing tips.

![](https://adamtheautomator.com/wp-content/uploads/2025/06/featured-image-6.png)

### [How to Add Timeouts to Pester Tests with PowerShell Runspaces](/pester-test-timeout-runspaces/)

Prevent Pester tests from hanging indefinitely using PowerShell runspaces. Learn to handle variable scoping, module loading, TestDrive access, and stream capture challenges with timeout protection.

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
