# $t format/contents different from $g

**URL:** <https://forums.powershell.org/t/t-format-contents-different-from-g/11994>\
**Category:** PowerShell Help\
**Created:** [February 2, 2019, 9:27am UTC](https://forums.powershell.org/t/t-format-contents-different-from-g/11994 "2019-02-02T09:27:22Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jason-colotario](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jason-colotario](https://forums.powershell.org/u/jason-colotario)\
**Post date:** [February 2, 2019, 9:27am UTC](https://forums.powershell.org/t/t-format-contents-different-from-g/11994/1 "2019-02-02T09:27:22Z")

</div>

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 (C) 2012-2016 Mark Russinovich Sysinternals - [www.sysinternals.com](http://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

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [February 2, 2019, 9:52am UTC](https://forums.powershell.org/t/t-format-contents-different-from-g/11994/2 "2019-02-02T09:52:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![js2010](https://avatars.discourse-cdn.com/v4/letter/j/ebca7d/32.png) [@js2010](https://forums.powershell.org/u/js2010)\
**Post date:** [February 2, 2019, 11:02am UTC](https://forums.powershell.org/t/t-format-contents-different-from-g/11994/3 "2019-02-02T11:02:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![postanote](https://avatars.discourse-cdn.com/v4/letter/p/ebca7d/32.png) [@postanote](https://forums.powershell.org/u/postanote)\
**Post date:** [February 2, 2019, 3:58pm UTC](https://forums.powershell.org/t/t-format-contents-different-from-g/11994/4 "2019-02-02T15:58:05Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![jason-colotario](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jason-colotario](https://forums.powershell.org/u/jason-colotario)\
**Post date:** [February 3, 2019, 11:08pm UTC](https://forums.powershell.org/t/t-format-contents-different-from-g/11994/5 "2019-02-03T23:08:52Z")

</div>

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 (C) 2012-2016 Mark Russinovich Sysinternals - [www.sysinternals.com](http://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 (C) 2012-2016 Mark Russinovich Sysinternals - [www.sysinternals.com](http://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\>

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:33pm UTC](https://forums.powershell.org/t/t-format-contents-different-from-g/11994/6 "2024-05-16T20:33:20Z")

</div>

Closed on May 16, 2024, 8:33pm UTC


