Pinging an array of ip addresses concurrently in PowerShell

廉价感情. 提交于 2019-12-12 01:59:23

问题


I have an array of objects with properties "IP" for storing an ip address and "LastAlive" for storing the date that the server last responded to a ping.

In order to fill the LastAlive properties I use the following function:

function Update-AliveStatus ($nodes)
{
    foreach ($node in $nodes)
    {
        $alive = Test-Connection $node.IP -Quiet -Count 2
        if ($alive -eq $true)
        {
            $node.LastAlive = (Get-Date)
        }
    }
    return $nodes
}

This works fine unless the list of IPs is long, in which case it takes ages to iterate through all of them. How can I modify the function to run the pings asynchronously and still return the filled array when all the pings are done?

来源:https://stackoverflow.com/questions/24930714/pinging-an-array-of-ip-addresses-concurrently-in-powershell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!