在这里我的脚本,基本上它刷新服务,一切工作正常,直到之后的最后状态检查Start-Sleep 25
。 它不断拉它收到的第一个状态(我在这个脚本夫妇检查状态和它使用的第一个状态,而不是重新检查它的)。
例如,如果服务处于脱机状态,它会使用首次检查时所获得的第一个离线状态,并显示它的服务已经开启之后。 任何方式展现了脚本重新检查状态并显示它,而不是使用第一个?
$services = "RTCRGS"
$SvrName = 'CORPxxxx.xxxx.xxxx'
Get-Service -ComputerName $SvrName -Name $services | % {
Write-host "$($_.Name) on $SvrName is $($_.Status)"
if ($_.Status -eq 'stopped') {
Write-Host "Starting $($_.Name) in 5 sec..."
Start-Sleep 5
Write-Host "$($_.Name) is Starting, please wait..."
$_.Start()
Write-Host "Checking status of service, please wait for 25 sec..."
Start-Sleep 20
Write-Host "$($_.Name) on $SvrName is $($_.Status)"
} elseif ($_.Status -eq 'running') {
Write-Host "Restaring $($_.Name) in 5 sec..."
Start-Sleep 5
$_.Stop()
Start-Sleep 5
Write-Host "$($_.Name) is Starting, please wait..."
$_.Start()
Write-Host "Checking status of service, please wait for 25 sec..."
Start-Sleep 25
Write-Host "$($_.Name) on $SvrName is $($_.Status)"
}
}