PowerShell Mass Test-Connection

前端 未结 3 813
野趣味
野趣味 2021-01-05 12:34

I am attempting to put together a simple script that will check the status of a very large list of servers. in this case we\'ll call it servers.txt. I know with Test-Connect

3条回答
  •  自闭症患者
    2021-01-05 13:14

    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!

提交回复
热议问题