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!



#pings an IP roughly every second and logs it to a logfile

#instructions: Replace $ip and $logFile variables

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

    $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 *