在PowerShell中并发ping ip地址数组

在PowerShell中并发ping ip地址数组,powershell,powershell-3.0,Powershell,Powershell 3.0,我有一个对象数组,属性“IP”用于存储IP地址,“LastAlive”用于存储服务器上次响应ping的日期 为了填充LastAlive属性,我使用以下函数: function Update-AliveStatus ($nodes) { foreach ($node in $nodes) { $alive = Test-Connection $node.IP -Quiet -Count 2 if ($alive -eq $true)

我有一个对象数组,属性“IP”用于存储IP地址,“LastAlive”用于存储服务器上次响应ping的日期

为了填充LastAlive属性,我使用以下函数:

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
}
除非IP列表很长,否则这很好用,在这种情况下,迭代所有IP都需要很长时间。如何修改函数以异步运行ping,并在所有ping完成后仍返回填充的数组

或者更好: