如何在 Powershell 中停止持续的 PING

大卫

我有一个 Powershell 脚本,它关闭运行良好的服务器列表,但部分代码应该持续 PING,直到服务器报告关闭。

foreach ($line in Get-Content $GetLocation) {
    if($line -match $regex){
        echo "Server Name = $line "
#        Stop-Computer -ComputerName $Line -Confirm
         ping $line -t
    }
}

PING返回“请求超时”的无响应时,有没有办法让脚本停止开关T是正确的开关吗?对此有何建议?

道格·梅森

你不想要一个连续的 ping,你想连续 ping 直到它失败。

foreach ($line in Get-Content $GetLocation) {
    if($line -match $regex){
        echo "Server Name = $line "
#        Stop-Computer -ComputerName $Line -Confirm
         while((Test-Connection $line -Count 1 -Quiet) -eq $true){}
    }
}

您可能也想在那里睡一觉。

foreach ($line in Get-Content $GetLocation) {
    if($line -match $regex){
        echo "Server Name = $line "
#       Stop-Computer -ComputerName $Line -Confirm
        while((Test-Connection $line -Count 1 -Quiet) -eq $true){
            Start-Sleep -Seconds 1
        }
    }
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章