Ping multiple computers in PowerShell

It came to my attention today that not everyone is spat out of the womb knowing how to test the network connection to a list of computers in PoSH. Some use cases for this one-liner could be…

  • Testing guest connectivity on a set of vMotions/LiveMigrating VM’s
  • ‘Monitoring’ the progress of automated/batch processes involving host restarts, for example VMware Update Manager host/guest patching
  • Rudimentary confirmation of node system load when testing load-balanced farms, increased response time being a sign of significantly increased system pressure

It’s pretty easy to do this. The method relies on the ability of the Microsoft Management Powershell Module cmdlet, Test-Connection, to accept a comma-separated list of hostnames.

Example as follows:

Test-Connection -ComputerName TESTPC1,TESTPC2,TESTPC3 -Count 100

Example (redacted) output:

As you can see, the Test-Connection cmdlet is alternating between the three listed hosts.  The output is superior to our good friend ping, exposing more data in a tabulated presentation with failed connections even coming up in attention-grabbing red text! The cmdlet has several handy switches outlined here. In case the power of having an honest-to-goodness queriable object pumped out by your connectivity verifier, rather than a string dump, is not self evident (think scripting scenarios people!), you can find a decent overview at the computerperformance.co.uk site.

Leave a Reply