I'm looking for an example that can break out of the current command if it runs for longer than say, 1 minutes, which would allow me to re-run it.
(我正在寻找一个示例,如果该命令运行超过一分钟(例如1分钟),则该示例可能会中断运行,这将允许我重新运行该命令。)
Here is my script :
(这是我的脚本:)
$ServiceName = 'service'
$arrService = Get-Service -Name $ServiceName
while ($arrService.Status -ne 'Running')
{
Start-Service $ServiceName
write-host $arrService.status
write-host 'Service starting'
Start-Sleep -seconds 3
$arrService.Refresh()
if ($arrService.Status -eq 'Running')
{
Write-Host 'Service is now Running'
}
}
ask by Arbelac translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…