powershell - Test-Connection Performance Better with HostName -


running test-connection ip address takes considerably longer running same command server's hostname.

however; if add -quiet parameter performance same (ip fraction faster, may expect).

using measure-command anomaly not show up; presumably quirk of output not being displayed.

the below code more accurately reflects anomaly seen:

$begin=(get-date).ticks;test-connection '123.45.67.89'; $a=((get-date).ticks - $begin) $begin=(get-date).ticks;test-connection 'myhostname'; $b=((get-date).ticks - $begin) $a-$b 

colleagues have reproduced same issue on machines.

question: aware of may cause this? i.e. suspect it's bug (and have reported such), implies there's clever going on powershell may work differently depending on whether output displayed or not / causing quantum-like effect; it's not running commands given in order, doing (de)optimisation under covers.

my environment

os: ms windows 7 pro sp1

$psversioninfo:

name                           value                                   ----                           -----                                                                                                                                                   psversion                      4.0                                      wsmanstackversion              3.0                                      serializationversion           1.1.0.1                                  clrversion                     4.0.30319.18444                          buildversion                   6.3.9600.16406                           pscompatibleversions           {1.0, 2.0, 3.0, 4.0}                     psremotingprotocolversion      2.2 

ms connect bug

https://connect.microsoft.com/powershell/feedbackdetail/view/1578010/test-connection-performance-with-ip-and-output

i did wireshark trace while running test-connection , without quiet switch parameter, supplying ipv4 address computername parameter.

when quiet switch omitted, powershell seems send not 1, 6 netbios name queries target machine, after returns formatted output.

if assign output test-connection, returns right away, pipe format-table, hangs , sends nbstat queries again


the root cause not test-connection cmdlet itself, formatted output. 1 of properties (ipv4address) scriptproperty , has following definition:

ps c:\> $ping = test-connection -computername 10.0.0.101 -count 1 ps c:\> get-member -inputobject $ping -name ipv4address | select-object -expandproperty definition system.object ipv4address {get=$iphost = [system.net.dns]::gethostentry($this.address)                     $iphost.addresslist | ?{ $_.addressfamily -eq [system.net.sockets.addressfamily]::internetwork } | select -first 1;} 

so, when output shown, [system.net.dns]::gethostentry(10.0.0.101) called calculate ipv4address - causes waiting time


if don't care moot resolution of ip address, use select-object prevent calculation , output of ipv4address:

test-connection -computername 10.0.0.101 -count 1 | select address,statuscode 

Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -