PowerShell Mass Test-Connection

Test-Connection has a -AsJob switch which does what you want. To achieve the same thing with that you can try:

Get-Content -path C:\Utilities\servers.txt | ForEach-Object { Test-Connection -ComputerName $_ -Count 1 -AsJob } | Get-Job | Receive-Job -Wait | Select-Object @{Name='ComputerName';Expression={$_.Address}},@{Name='Reachable';Expression={if ($_.StatusCode -eq 0) { $true } else { $false }}} | ft -AutoSize

Hope that helps!


I have been using workflows for that. Using jobs spawned to many child processes to be usable (for me).

workflow Test-WFConnection {
  param(
    [string[]]$computers
  )
    foreach -parallel ($computer in $computers) {        
        Test-Connection -ComputerName $computer -Count 1 -ErrorAction SilentlyContinue
  }
}

used as

Test-WFConnection -Computers "ip1", "ip2"

or alternatively, declare a [string[]]$computers = @(), fill it with your list and pass that to the function.

Tags:

Powershell