If you’ve ever worked with a computer network and needed to test the system’s connection via the Ping command, you’ve likely run into the same challenges as I. There are many ping utilities out there like SolarWinds, PingPlotter, PingAssist, LIBERATION, or just the ol’ command prompt. Some are free or built into Windows, but I need something simple for today’s operations.
Here’s a situation I often encounter as a System Administrator: A user calls or puts in a work order saying that their LAN/WAN connected computer seems to be slow to retrieve an email, web or server address. My next step is usually in the Windows Command Prompt (In Windows 7, click Start and type in Cmd.exe” and then type in: Ping ComputerName -t b> This causes the computer to send a Ping request over the network to the desired location. and going, filling the screen and then scrolling off.
But what if you miss a drop? What if you get distracted?
It’s not usually about “if” I’m distracted, it’s “when”. The command window can only handle so many pings before the volumes overflow the buffer capacity of the program’s memory. There is also no “historical” aspect, as once again the data volumes from the screen into the data bit in the bucket in the sky.
I needed a simple visual solution to paint a computer or IP address that could be derived from the Command Prompt or directly via a PowerShell script. Through the power of PowerShell I came up with a solution that I use almost every day on my network. I could say “Powershell Ping” or “Ping Powershell”, but, hey, why not a fancy name, right? And so “PowerPing” was born!
PowerPing Features:
Display IP address (if available) after Maximum Pings is reached
Product Foreground and Maecenas colors
Product delay between pings
Produced the largest number of Pings (I tested it with 99,999,999 – but surely, it never reached the end!)
Configurable Column Width (65 works best in most cases)
The running time stamp is displayed in the right column
Top code showing hostname, Ping Delay, and configured Ping attempts
Platforms Tested / Requirements
This has been tested successfully on Windows XP and Windows 7 32-bit using PowerShell version 2.0. In order to get this up and running, the Powershell ExecutionPolicy needs to be configured. I set mine to “remote”. (You can view and change the security policy from within PowerShell with ExecutionPolicy and Set-ExecutionPolicy).
Getting everything running
I usually launch my Powershell scripts from the Windows Command Prompt using the following format: “PP HostName”. To download this, we need two files, both placed in the Windows path. (I save my script in a special folder and add this folder to the system variable “Path=”, but you can also put the two files in the Windows or WindowsSystem directories.
Creating the Pp.Bat file:
Copy the code between the “Begin” and “End” blocks, and write it as “PP.bat” (without the quotes, of course)
|| Start the PP.Bat Script
:: PowerPing Batch File – PP.BAT
@echo off
echo PowerPing.ps1 %* | powershell -Command –
|| The end of PP.Bat Script
Creating file PowerPing.ps1:
Copy the code between the “Begin” and “Fin” script blocks, and save it as “PowerPing.ps1”
PowerPing.ps1
|| Start the PowerPing.ps1 Script
# PowerPing by Ron Masters — http://contributor.yahoo.com/user/626225/ron_masters.html
# The color values are “Black, DarkBlue, DarkGreen, DarkCyan, DarkRed, DarkMagenta,
# DarkYellow, Gray, DarkGray, Blue, Green, Cyan, Red, Magenta, Yellow, White”.
$MaxPings = 3000
$PingDelaySeconds = 1
$ColumnWidth = 65
$BannerBackground = “Blue”
$ColorPingBackground = “Black”
$ColorPingForeground = “DarkGreen”
$BackgroundColorNoPing = “Black”
$ForegroundColorNoPing = “Red”
$TimeStampBackground = “Black”
$TimeStampForeground = “Gray”
$ExtraSpace = ” ”
$Name=($args[0])
$b=1
$g = 1
$ResetV = 1
$ Datetime = Get-Date -format g
$ TimeNow = Get-Date -format T
$IPAddress=get-wmiobject win32_pingstatus -Filter “Address=’$Name'” | Select-Object IPV4Address | Form-list
Write-Host ‘r
Write-Host PowerPing “-” $name $ExtraSpace $ExtraSpace $ExtraSpace $ExtraSpace “PingDelay=”$PingDelaySeconds” Secs MaxPings=”$MaxPings $ExtraSpace -background $BannerBackground -foreground “album”
for($i=i; $i -le $MaxPings; $i++)
{$ALive=ut-wmiobject win32_pingstatus -Filter “Address=’$Name” | Select-Object status code
$b++
start-sleep $PingDelaySeconds
if ($ALive.statuscode -eq 0)
{
# —– IP/Hostname Pinging ——————–
$TimeNow = Get-Date -format t
$ResetV++
if($ ResetV -gt 1) write-exercise {“_” -nonewline -background $ColorPingBackground -foreground $ColorPingForeground}
}
something else
{
# —– IP/Hostname Not Pinging —————
$TimeNow = Get-Date -format t
#$ DownTime = Get-Date -format t
# $TimeNow = $DownTime
$g++
$ResetV++
if($g -lt 3){write-guest “+-” -nonewline -background $BackgroundColorNoPing -foreground “red”}
if($g -gt 3) {write-guest “-” -nonewline -background $BackgroundColorNoPing -foreground “red”}
}
if((($b -gt $ColumnWidth) and ($ResetV -gt 2))){ write-host ” ” $TimeNow -background $TimeStampBackground -foreground $TimeStampForeground `r}
if($b -gt $ColumnWidth){$b=1}
}
To write, Hostia ‘r
$IPAddress
|| The end of the script
Running PowerPing
From the command prompt, type pp and the system name or IP address (for example: pp 192.168.1.1; or, pp www.yahoo.com, or pp hostname ) as you would like to ping. The PP.bat file will pass the hostname variable in PowerPing.ps1. The first signal should show that it is the highest signal, then – if the target system is pingable – a series of green s will start to move. transversal screen. When the end of the line is reached, the time of the figure is shown, and the next line begins to be drawn. If the system can’t be tapped, first it will show a red “+” (I wanted something that would catch my eye), then it will flash more red. If the system reaches again, the trace line turns green. Look through the images 1 shot 5 that ping this article for examples of different types of responses. When the script rolls over the configured maximum value, the IP address of the host is displayed and the script is terminated.
Trigger colors can be displayed on several items. I’ve included a note at the beginning of the PowerPing.ps1 file that includes the possible color choices that can be used. (You recognize that there are statements when the line starts with “#”) Try some different combinations of color. Maybe you’ll find a color combo that matches your style.
Adjust “Ping Delay”, “Column Width” and “Maximum Pings” just change the number next to the appropriate variable, save and re-run the script.
Final Thoughts
I’ve heard the saying, it’s better to shine than to work harder? I’ve explored that before in my Powershell Tips and Tricks and Listing Printers with Powershell articles. Now with PowerPing, I was able to use the power of Powershell to give me a live visual report of how consistent or unstable the connection is. This do-it-yourself script is now an essential yeast utility that will be in my system admin toolkit for a long time.
Happy writing… and happy pinging!