In the past I have used different tools to ping a list of computers. One of the nicest was a rather old version of WhatsUpGold. It was quick to install and simple to use.

Now we have PowerShell on almost every Windows computer I wanted to have a solution in PowerShell, so I’m not required to install any dedicated ping software anymore.

Here’s a simple script I wanted to share with you. It allows you to ping several computers at once. When a ping is over a configurable threshold output is displayed in yellow or red.

Enjoy!

Dimitri

 

MultiPing: ping several computers

MultiPing: ping several computers

Function MultiPing {
<#
.SYNOPSIS
Sends a ping to a specified host. Colors the output to indicate latency.
.DESCRIPTION
Version 1.1. Provides a simple network monitoring solution, without the need to install any software.
.EXAMPLE
MultiPing ServerX
Sends a ping to ServerX every second. Repeats forever.
.EXAMPLE
MultiPing ServerX, ServerY, 10.1.1.254, www.google.com
Sends a ping to two servers, the IP address of the default gateway and a webserver on the internet
#>

param($computername="localhost", [bool]$repeat=$false, [int]$PingCritical=8, [int]$PingWarning=4)

Write-Host "Pinging $($computername.count) remote systems, repeat is $repeat. Interrupt with Ctrl-C." -Foregroundcolor green
Write-Host "Thresholds: critical=$PingCritical, warning=$PingWarning" -Foregroundcolor green
Do {
  $computername | foreach {
    $a = Test-Connection $_ -Count 1 -ErrorAction SilentlyContinue
    if (!$?) { Write-Host "$_ --- " -nonewline -fore red }   
    else {
      $msg = "$($a.Address) $($a.ResponseTime.ToString().PadRight(4))"
      if     ($a.ResponseTime -ge $PingCritical) { write-host $msg -nonewline -fore red }
      elseif ($a.ResponseTime -ge $PingWarning)  { write-host $msg -nonewline -fore yellow }
      else                                       { write-host $msg -nonewline }
    }
  }
Write-Host ""
Start-Sleep (1)
} while ($repeat)
}

1 Comment on Ping several computers with PowerShell: MultiPing

  1. Ian M says:

    Exactly what I was looking for – many thanks!