[英]How to stop a continuing PING in Powershell
我有一个 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
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.