Conditional psping64 output to file?

Hi everyone,

I am new to PowerShell, and I am in a bit of a pickle attempting to create a conditional output for psping64 (Microsoft SysInternals tool).

The background issue:
I am troubleshooting high ping spikes on Wireless using Process Monitor, psping64.exe and my wits. The high ping spikes occur at various times, more while playing online games and less while browsing, on a wireless network. I know the source of the high ping spikes originates from my own machine and I want to isolate the process generating this issue.

What I want to do is use psping64 to run as many pings as possible and output all ping responses over 100 ms to a file, together with timestamps. I will then use the timestamps to filter Process Monitor events and isolate the troublesome process. A simple plan, in theory.
I got as far as creating a command in PowerShell which runs ping very quickly and outputs everything to a file, together with timestamps. The command is

.\psping64.exe -t -i 0 192.168.2.1 |Foreach{“{0} - {1}” -f (Get-Date),$_} | Tee-object -FilePath ping_log.txt

The output (excerpt) looks like this:

24-Jan-20 16:17:33 - Reply from 192.168.2.1: 2.04ms
24-Jan-20 16:17:33 - Reply from 192.168.2.1: 2.09ms
24-Jan-20 16:17:33 - Reply from 192.168.2.1: 2.07ms
24-Jan-20 16:17:33 - Reply from 192.168.2.1: 2.02ms
24-Jan-20 16:17:33 - Reply from 192.168.2.1: 2.07ms
24-Jan-20 16:17:33 - Reply from 192.168.2.1: 2.00ms
24-Jan-20 16:17:33 - Reply from 192.168.2.1: 2.08ms
24-Jan-20 16:17:33 - Reply from 192.168.2.1: 2.06ms
24-Jan-20 16:17:33 - Reply from 192.168.2.1: 2.02ms
24-Jan-20 16:17:33 - Reply from 192.168.2.1: 2.04ms
24-Jan-20 16:17:33 - Reply from 192.168.2.1: 2.13ms
24-Jan-20 16:17:33 - Reply from 192.168.2.1: 2.00ms
24-Jan-20 16:17:33 - Reply from 192.168.2.1: 2.01ms
24-Jan-20 16:17:33 - Reply from 192.168.2.1: 2.61ms

What I want to do is refine this command using a script in such a way that it only outputs data with “Reply from 192.168.2.1:” value greater than 100 ms, for example “24-Jan-20 16:38:26 - Reply from 192.168.2.1: 3000.17ms”. I imagine I would need to manipulate the output as a string and isolate the ping reply number, then if the condition met is true, putput the whole string to the txt file, but I am at a loss as to how to implement that.

Help would be much appreciated!

Thank you in advance!

You might want to try PowerShell’s built-in Test-Connection command instead of psping64.exe, but if you want to stay with that you could parse the text to pull out the ms then filter on the pipeline with a Where-Object to meet your criteria. Here is an example of how you could parse the text (change the static text with your variable $_).

[double]("Reply from 192.168.2.1: 2.04ms" -replace "(.+:\s)|(ms)","")

Recommend research Test-Connection, Where-Object, About_Comparison_Operators, About_Regular_Expressions

Hi Mike,

Thank you for your reply.
The Test-Connection built-in command does not allow for pings to be sent quickly, the -Delay parameter can’t be set below 1, meaning that the fastest pace is 1 pings per second. However, using your example and recommendations, I have put together the following script:

.\psping64.exe -t -i 0 192.168.2.1 |Foreach{

$pingsize = [double]($_ -replace “(.+:\s)|(ms)”,“”)

if ($pingsize -gt 100)
{
$adddate = Get-Date -Format “yyyy/MM/dd HH:mm:ss:fff”
“{0} - {1}” -f ($adddate),($pingsize)
}
else {}
} | Tee-object -FilePath ping_log.txt

It is currently running, I tested it against lower ping values (2) and it does what it’s supposed to.
I guess there are ways to optimize and clean the code, but as a beginner I am satisfied with what I have accomplished so far :slight_smile: