$t format/contents different from $g

Is $t special? Why is $t output format different from $g?

$t and $g are both of type system.string…

PS C:\users\name\downloads> $t = psping localhost
PS C:\users\name\downloads> $t
PsPing v2.10 - PsPing - ping, latency, bandwidth measurement utility Copyright © 2012-2016 Mark Russinovich Sysinternals - www.sysinternals.com Pinging ::1 with 32 bytes of data: 5 iterations (warmup 1) ping test: Reply from ::1: 0.59ms Reply from ::1: 1.83ms Reply from ::1: 1.51ms Reply from ::1: 1.55ms Reply from ::1: 1.73ms Ping statistics for ::1: Sent = 4, Received = 4, Lost = 0 (0% loss), Minimum = 1.51ms, Maximum = 1.83ms, Average = 1.65ms

PS C:\users\name\downloads> $g = psping localhost
PS C:\users\name\downloads> $g

Pinging xxxxxxxxxxx [::1] with 32 bytes of data:
Reply from ::1: time<1ms
Reply from ::1: time<1ms
Reply from ::1: time<1ms
Reply from ::1: time<1ms

Ping statistics for ::1:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms

I cannot reproduce the behaviour you’re describing. Did you try to restart your console session?

Are $t and $g the same type?

PS C:\users\me> $t.gettype()                                                  

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     String                                   System.Object

PS C:\users\me> $g.gettype()                                                  

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     Object[]                                 System.Array

I can get your result if I cast $t to a string instead of a string array or object array:

PS C:\users\me> [string]$t = psping localhost

PS C:\users\me> $t

PsPing v2.10 - PsPing - ping, latency, bandwidth measurement utility Copyright (C) 20
12-2016 Mark Russinovich Sysinternals - www.sysinternals.com  Pinging ::1 with 32 byte
s of data: 5 iterations (warmup 1) ping test:  Reply from ::1: 19.51ms Reply from ::1:
 0.57ms Reply from ::1: 0.58ms Reply from ::1: 0.59ms Reply from ::1: 0.60ms  Ping sta
tistics for ::1:   Sent = 4, Received = 4, Lost = 0 (0% loss),   Minimum = 0.57ms, Max
imum = 0.60ms, Average = 0.58ms

It’s happened to me too. You might think that the variable forgets its type when you use it for something else, but it doesn’t.

ditto to what Olaf and js is stating. doing the following in the consolehost/ISE/VSCode all return the same results.

($t = D:\Tools\psping -accepteula localhost)
([string]$t = D:\Tools\psping -accepteula localhost)


PsPing v2.10 - PsPing - ping, latency, bandwidth measurement utility
Copyright (C) 2012-2016 Mark Russinovich
Sysinternals - www.sysinternals.com

Pinging ::1 with 32 bytes of data:
5 iterations (warmup 1) ping test:
Reply from ::1: 0.83ms
Reply from ::1: 0.54ms
Reply from ::1: 1.26ms
Reply from ::1: 0.60ms
Reply from ::1: 1.27ms

Ping statistics for ::1:
  Sent = 4, Received = 4, Lost = 0 (0% loss),
  Minimum = 0.54ms, Maximum = 1.27ms, Average = 0.92ms



PsPing v2.10 - PsPing - ping, latency, bandwidth measurement utility Copyright (C) 2012-2016 Mark Russinovich Sysinternals - www.sysinternals.com  Pinging ::1 with 32 bytes of data: 5 iterations (warmup 1) ping test:  Reply from ::1: 1.04ms Reply from ::1: 0.63ms Reply from ::1: 0.69ms Reply from ::1:
1.15ms Reply from ::1: 1.25ms  Ping statistics for ::1:   Sent = 4, Received = 4, Lost = 0 (0% loss),   Minimum = 0.63ms, Maximum = 1.25ms, Average = 0.93ms


($g = D:\Tools\psping -accepteula localhost)
([string]$g = D:\Tools\psping -accepteula localhost)


PsPing v2.10 - PsPing - ping, latency, bandwidth measurement utility
Copyright (C) 2012-2016 Mark Russinovich
Sysinternals - www.sysinternals.com

Pinging ::1 with 32 bytes of data:
5 iterations (warmup 1) ping test:
Reply from ::1: 0.74ms
Reply from ::1: 1.04ms
Reply from ::1: 1.06ms
Reply from ::1: 0.94ms
Reply from ::1: 1.08ms

Ping statistics for ::1:
  Sent = 4, Received = 4, Lost = 0 (0% loss),
  Minimum = 0.94ms, Maximum = 1.08ms, Average = 1.03ms



 PsPing v2.10 - PsPing - ping, latency, bandwidth measurement utility Copyright (C) 2012-2016 Mark Russinovich Sysinternals - www.sysinternals.com  Pinging ::1 with 32 bytes of data: 5 iterations (warmup 1) ping test:  Reply from ::1: 0.98ms Reply from ::1: 0.51ms Reply from ::1: 0.65ms Reply from ::1:
1.14ms Reply from ::1: 1.47ms  Ping statistics for ::1:   Sent = 4, Received = 4, Lost = 0 (0% loss),   Minimum = 0.51ms, Maximum = 1.47ms, Average = 0.94ms

Question: Why are you using both $t and $g?
Just curious.
Also, why psping, vs, just ping or Test-Connection, Test-NetConnection for general liveliness validation?

Thanks everyone! I ended up restarting my console and then I got consistent results. I must have strongly typed my $t variable as [string] and not strongly typed $g earlier on in my testing.

I wanted to strongly type $t for my test so that I could then use $t.contains(“0% loss”) as the condition in my connectivity script. I still use test-netconnection, however I think it’s best to build a script with three concurrent successful tests to any port to validate it is open. Another reason I like PSPing utility is that it runs very vast and does not try to resolve DNS. I’ve also found that test-netconnection cmdlet is much slower that PSPing.

PS C:\scripts> [string] $t = psping localhost
PS C:\scripts> [string] $g = psping localhost

PS C:\scripts> $t.gettype()

IsPublic IsSerial Name BaseType


True True String System.Object

PS C:\scripts> $g.gettype()

IsPublic IsSerial Name BaseType


True True String System.Object

PS C:\scripts> $t
PsPing v2.10 - PsPing - ping, latency, bandwidth measurement utility Copyright © 2012-2016 Mark Russinovich Sysinternals - www.sysinternals.com Pinging ::1 with 32 bytes of data: 5 iterations (warmup 1) ping test: Reply from ::1: 0.63ms Reply from ::1: 0.48ms Reply from ::1: 0.49ms Reply from ::1: 0.51ms Reply from ::1: 0.48ms Ping statistics for ::1: Sent = 4, Received = 4, Lost = 0 (0% loss), Minimum = 0.48ms, Maximum = 0.51ms, Average = 0.49ms
PS C:\scripts> $g
PsPing v2.10 - PsPing - ping, latency, bandwidth measurement utility Copyright © 2012-2016 Mark Russinovich Sysinternals - www.sysinternals.com Pinging ::1 with 32 bytes of data: 5 iterations (warmup 1) ping test: Reply from ::1: 0.58ms Reply from ::1: 1.41ms Reply from ::1: 1.31ms Reply from ::1: 1.41ms Reply from ::1: 0.68ms Ping statistics for ::1: Sent = 4, Received = 4, Lost = 0 (0% loss), Minimum = 0.68ms, Maximum = 1.41ms, Average = 1.20ms
PS C:\scripts>