Test-Connection oddities
Posted by: Richard Siddaway
I’ve playing around with Test-Connection because I wanted to set up a long running WMI based job and I thought that pinging a machine lots of times would be a good way to do it. Test-Connection uses the Win32-PingStatus class.
I started with this
PS> Test-Connection -ComputerName . -Count 4
Source Destination IPV4Address IPV6Address Bytes Time(ms)
—— ———– ———– ———– —– ——–
RSLAPTOP01 localhost 127.0.0.1 ::1 32 0
RSLAPTOP01 localhost 127.0.0.1 ::1 32 0
RSLAPTOP01 localhost 127.0.0.1 ::1 32 0
RSLAPTOP01 localhost 127.0.0.1 ::1 32 0
Nothing special there.
I then tried this
PS> Test-Connection -ComputerName . -Count 4 -Quiet
False
Huh?
PS> Test-Connection -ComputerName localhost -Count 4 -Quiet
True
Odd
PS> Test-Connection -ComputerName $env:COMPUTERNAME -Count 4 -Quiet
True
Very odd – seems like “.” isn’t liked when running –Quiet. Another good reason to avoid it
I then tried it as a job
PS> Test-Connection -ComputerName . -Count 4 -AsJob
Id Name State HasMoreData Location Command
– —- —– ———– ——– ——-
3 Job3 Running False . Test-Connection
PS> Get-Job
Id Name State HasMoreData Location Command
– —- —– ———– ——– ——-
1 Job1 Completed True . Test-Connection
3 Job3 Completed True . Test-Connection
PS> Receive-Job -Id 3
Source Destination IPV4Address IPV6Address Bytes Time(ms)
—— ———– ———– ———– —– ——–
RSLAPTOP01 localhost 127.0.0.1 ::1 32 0
Only one ping is returned instead of the 4 I was expecting.
Not major problems but something to remember




