Hey there checkyourlogs.net fans!

Today I needed to ping sweep an entire subnet from a Windows Server 2012 box. Simple, right? There are plenty of free and paid tools out there ready to perform this task. My dilemma was, and is, I don’t want to install additional software, no matter how small and tight, on servers. Especially anything requiring additional licensing or support software such as, GASP, JAVA. Nope, nada, not on my watch. Keep server configurations clean and concise is my motto.

What to do? My need still existed, and oh, by the way was fairly urgent. PowerShell to the rescue!

The original idea for this code comes from a blog post offered a few years ago by my friend, PowerShell MVP Jeff Hicks. I tweaked the code for my current needs, adding variables as required and sending the results to a .csv file easily imported int Excel where sorting and filtering is easy. I added comments explaining the purpose of each variable. No need to rehash those. Here’s the code in action.

Those looking closely, probably notice one screenshot uses VSCode, while the other leverages the good ‘ole ISE. The server I ran this script on is 2012 R2. The ISE was already installed. The ISE proved once again that old doesn’t mean useless. The ISE ran this ping sweep code without missing a beat.

Don’t worry, I won’t make you retype the code from a screenshot. Here it is in easy to cut and paste form, ready for work.

# Subnet identifier for ping sweep
$subnet = "10.113.4"

# Host IP to start ping sweep
$start = 1

# Host IP to finish ping sweep
$end = 254

# Number of times to attempt each ping
$ping = 1

# Path and filename for results file
$OutPath ="C:\Temp\Output.csv"

While ($start -le $end) {
$IP = "$subnet.$start"
$Test = Test-Connection -ComputerName $IP -count $ping -Quiet
Write-Host "$IP,$Test"
Add-Content -LiteralPath $OutPath -Value "$IP,$Test"

The code in this post, by design, is quite unrefined. My goal is showing how a little PowerShell goes a long way in helping us IT Pros get our jobs done, day in and day out. In coming blog posts, I’ll refine this code into a function, add parameters, and even add it into my custom “ITPro Toolkit” PowerShell Module. These mods, among other things, will allow us to look for specific results, such as just hosts responding to our pings.

Thanks everyone! I hope this code helps in your day to day IT troubleshooting challenges!

John Sr.