How can I use multiple Test-Connection
cmdlets and put them all in one Out-GridView
, or is there another solution to what I'm trying to do here?
The point is to be able to ping multiple adresses after one another and have it all appear in the same window.
Run multiple test-connection for one gridview output
2.4k Views Asked by Thom Ernst At
3
There are 3 best solutions below
1

you can use this command :
$tests= Test-Connection -ComputerName $env:COMPUTERNAME
$tests+= Test-Connection -ComputerName $env:COMPUTERNAME
$tests| Out-GridView
0

Test-Connection
can take a array of computer names or addresses and ping them. It will return a line for each ping on each computer but you can use the -Count
parameter to restrict it to 1 ping. You can also use the -AsJob
to run the command as a background job.
$names = server1,server2,serverN
Test-Connection -ComputerName $names -Count 1 -AsJob | Wait-Job | Receive-Job
You will get back a list of Win32_PingStatus object that are show as
Source Destination IPV4Address IPV6Address Bytes Time(ms)
------ ----------- ----------- ----------- ----- --------
If the time column (ResponseTime property) is empty, there is no ping replay, the server is offline. You can filter on this.
Feed your list of IP addresses (or hostnames) into a
ForEach-Object
loop runningTest-Connection
for each address, then pipe the result intoOut-GridView
:Note that this can be quite time-consuming, depending on the number of addresses you're checking, because all of them are checked sequentially.
If you need to speed up processing for a large number of addresses you can for instance run the checks as parallel background jobs:
Too much parallelism might exhaust your system resources, though. Depending on how much addresses you want to check you may need to find some middle ground between running things sequentially and running them in parallel, for instance by using a job queue.