So the boss emails you a list of computers and wants you to check if each of them are available on the network. You could open a command prompt, type PING and the first name, wait for a response, PING the second, ad nauseum. If there’s two names on the list, fine. How many on this list? 183. Yuck! Sounds like a job for… PowerShell!
Okay — let’s find a PowerShell feature that lets me ping a computer. Get-Command is the usual way to go about that, but in this case, I’m not getting a lot of luck. I see the PING executable, and other stuff I don’t need, but nothing in PowerShell. Here’s a wild idea — let’s try using Get-Help and see what we find.
Interesting — there’s a Test-Connection cmdlet that claims to be able to send PINGs to one or more computers. Sounds perfect. Let’s take a close look at the help file for Test-Connection.
I like the idea of the –Quiet parameter for a simple TRUE/FALSE evaluation of whether the computer is on the network. Having an object to interrogate might be useful in a later script, but for now, I’ll leave that Win32_PINGSTATUS object alone. What I really want to do is get a list of which computers are not currently accessible. So strategically, I want to iterate through my list of computer names, and for each one of them, if it isn’t ping-able (is that a word? Is now) then I want to get a message that says so. So how about something like this (click on the screenshot for a larger image)?
It’s a good start. But I don’t know which of the computers from my file are the ones returning true and false. Also, let’s assume I only want to know which computers are offline. Time to pull out the trusty old ‘if’ statement.
Hmmm. Those pesky rebels are at it again, it seems.
I like the output of this little one-liner. It’s a little slow, though. I can tweak it a bit by adding the –Count 1 parameter to Test-Connection, which instead of launching 4 ICMP packets sends One Ping Only (now, why am I hearing Sean Connery’s voice in my head all of a sudden?)