Test-Connection can ping multiple computers only sequentially, and it does not let you specify a timeout. So when you need to check a large number of systems, it is very slow.
A much faster way is to use the underlying WMI and instruct it to ping multiple systems simultaneously:
$ComputerName = 'powertheshell.com', 'powershellmagazine.com', 'powershell.com' $Timeout = 2000 $filter = 'Address="' + ($ComputerName -join """ and Timeout=$Timeout or Address=""") + """ and Timeout=$Timeout" Get-WmiObject -Class Win32_PingStatus -Filter $filter | Select-Object -Property Address, ProtocolAddress, ResponseTime, Timeout
The result comes in almost instantaneously:
Address ProtocolAddress ResponseTime Timeout ------- --------------- ------------ ------- powertheshell.com 2400:cb00:2048:1::6818:7c40 27 2000 powershellmagazine.com 184.108.40.206 117 2000 powershell.com 220.127.116.11 161 2000
When you look at the constructed WMI filter, it looks like this:
PS C:\> $Filter Address="powertheshell.com" and Timeout=2000 or Address="powershellmagazine.com" and Timeout=2000 or Address="powershell.com" and Timeout=2000
As you see, you can set the timeout for each individual computer.
Throughout this month, we'd like to point you to two awesome community-driven global PowerShell events taking place this year:
Europe: April 20-22: 3-day PowerShell Conference EU in Hannover, Germany, with more than 30+ speakers including Jeffrey Snover and Bruce Payette, and 60+ sessions (www.psconf.eu).
Asia: October 21-22: 2-day PowerShell Conference Asia in Singapore. Watch latest annoncements at www.psconf.asia
Both events have limited seats available so you may want to register early.