How to log ping condition

Hi, I’m PS noob. I am also a noob C++ programmer (I know the basics).

Is it possible to ping two servers indefinitely while only displaying/log ONLY when the latency is more than 100ms?

I have two monitors.
I’m gaming and sometime having bad connection to the game server.
The server IP will be either or
currently I open two Command Prompt windows and do :

ping -t
ping -t

separately in each window

So I look regularly to the CMD windows to check if there are any latency issues.

It would be convenience if the output only display when latency is above certain threshold and would be nicer if I can play a WAV file when the threshold is reached so that I could stay away from the fight for a while if latency is bad :slight_smile:

I looked into PowerShell and think it could solve this little problem. So I started learning it today :slight_smile:
I tried some IF statements and few FOR loops. Doesn’t work (doesn’t know how to make it work).
Is possible to do that with the condition mentioned? How?

Hi Areriff,

This seems like it may fit your needs:

$server = ''
$responseThreshold = 0
$processName = 'notepad++'
$soundFile = 'c:\WINDOWS\Media\notify.wav'

$loopOn = $true

while ($loopOn -eq $true)
    $ping = Test-Connection -ComputerName $server -count 1 | Select-Object ResponseTime
    $timeStamp = (Get-Date).ToShortTimeString()
    Write-Output "$timeStamp : $($ping.responsetime) ms"
    #Check response time against threshold, play sound if greater than or equal to.
    if ($ping.ResponseTime -ge $responseThreshold)
        $sound = New-Object System.Media.SoundPlayer
        $sound.SoundLocation = $soundFile
    #Check if process is still running, if not, exit loop.
    try { Get-Process -Name $processName -ErrorAction Stop | Out-Null}
    catch { $loopOn = $false }
    Start-Sleep 1

You can enter the site specific settings at the top including server address and response threshold (in ms).
I thought you probably want this to run only while your game is running, so it checks for the process, and exits the loop if it is not found. I used notepad++ for testing, so be sure to update that variable with the name of the game process. The datetime and response time will update in the console so you can see spikes and other activity if desired.

This is a test.

Do {
Test-Connection | Select-Object Address, 
IPV4Address, ResponseTime, ResponseTimeToLive | 
Where-Object {$_.ResponseTime -gt '100'}} While ($true)

Trevor’s code looks much better than this, but a quick bash :

$devices = '', ''

$hash = @()
    $devices | foreach {
        if ((Test-Connection $_ -count 2).ReponseTime -le 100) {
            $hash += @{ Normal= "$_ less than 100ms" } 
            $hash += @{ WARNING="$_ More than 100ms" } 
            $Hash | foreach { [PSCustomObject]@{
                Status = $_.keys | % { "$_" }
                Device = $_.Values | % { "$_" }

Great, thanks. I’ll study the suggestions and try it.