Ping results over time

This script was useful to me while tracking down a networking issue where packets were lost over a long period of time. I ran this script from 2 different endpoints and compared the times that the packets were dropped. Enjoy!

Source: http://avari.tech/access/pinglog.ps1

#***************************************************************************************#

#pinglog.ps1
#1/18/2016, trey@avari.tech
#pings an IP roughly every second and logs it to a logfile

#instructions: Replace $ip and $logFile variables

$ip = "4.2.2.1"
$logFile = "C:\users\csmith\Documents\working\pingOutput.txt"

while($true){
    $time = get-date | select DateTime
    $timeStr = $time.DateTime -replace " ","" -replace "2017","" #no comma #between year and time so deleted year
    $pingRes = ping -n 1 $ip
    $pingSplit = $pingRes.Split()

    if ($pingSplit[8] -eq "Reply"){$pingStr = $pingSplit[12]}
    else{$pingStr = "Failed"}

    add-content $logFile "$timeStr,$pingStr"
    write-host "$timeStr,$pingStr"
    start-sleep 1
}

Leave a Reply

Your email address will not be published. Required fields are marked *