Test Subnet with PowerShell

keyboardanalyzeA few years ago I published a PowerShell function to test IP addresses on a given subnet. I had an email the other day about it and I decided to refresh it. My new version adds a few bells and whistles that I think you might like. For example, you can now run it from a remote computer. In other words, you can ping IP addresses from another computer which might be helpful.

I’ve also added an option to resolve the IP address to a hostname using DNS. Because I don’t want to require anything on a remote computer, I am using the .NET DNS class to resolve the name. In addition, I have included a fallback resolution using NETBIOS. If you ask for resolution, and DNS doesn’t return a name, you can opt to use the NBTSTAT command to resolve the hostname. I use a regular expression pattern to pull the computername.

Here’s version 2.0 of Test-Subnet.

And to be clear, “subnet” may be a bit of a misnomer as I’m not calculating any addresses with a subnet mask. Instead you enter the base IPAddress, like 10.10.1.0 and then a range of host numbers between 1 and 254, which is the default by the way. The command will then test 10.10.1.1 through 10.10.1.254, or whatever you entered.

My script employs some other techniques you might find help such as splatting, parameter sets, Write-Progress and parameter validation. Here’s a screenshot of results that I’ve sent to Out-Gridview and then customized.

test-subnet

But since the command writes objects to the pipeline you could do whatever you wanted. I trust you’ll let me know what you think. Enjoy!!

2 thoughts on “Test Subnet with PowerShell”

I'd love to know what you think