我的状态不会更新,它会继续从以前的状态中拉出 [英] My status won't update and it keep pulling from the previous status

查看:33
本文介绍了我的状态不会更新,它会继续从以前的状态中拉出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里是我的脚本,基本上它刷新了服务,一切正常,直到 Start-Sleep 25 之后的最后一次状态检查.它不断提取它收到的第一个状态(我在这个脚本中有几个检查状态,它使用第一个状态而不是重新检查它).

Here my script, basically it refreshes service, everything is working fine until that last status check after Start-Sleep 25. It keeps pulling the first status that it received (I have couple check status in this script and it uses the first status instead of rechecking it).

例如,如果服务处于离线状态,它将使用第一次检查时获取的第一个离线状态,并在服务开启后显示.有什么方法可以让脚本重新检查状态并显示它而不是使用第一个?

For example, if the service is offline and it will use the first offline status that was acquired when checking for the first time and display it after the service have been turned on. Any way to show have the script recheck the status and display it instead of using the first one?

$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)"
    }
}

推荐答案

在start-sleep 20语句后做一个新的get-service来刷新状态

After the start-sleep 20 statement do a new get-service to refresh status

这篇关于我的状态不会更新,它会继续从以前的状态中拉出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆