如何检查挂起的重启? [英] How can I check for a pending reboot?

查看:135
本文介绍了如何检查挂起的重启?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图了解 Windows 机器需要或不需要重新启动的位置.但是,我的脚本抛出错误.

I am trying to get to know where reboot is required or not for a Windows machine. However, my script is throwing and error.

powershell "$key = Get-Item "HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired" -ErrorAction SilentlyContinue"

Error :
Get-Item : A positional parameter cannot be found that accepts argument
'Update\RebootRequired'.
At line:1 char:8
+ $key = Get-Item
HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Aut ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-Item], ParameterBindin
   gException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell
   .Commands.GetItemCommand

我在命令提示符"中运行此命令.不知道是什么意思!

I am running this command in "command prompt". Not sure what it means !

推荐答案

需要检查 2 个路径,一个 key,需要通过 WMI 查询配置管理器,以检查所有可能的位置.

You need to check 2 paths, one key and you need to query the configuration manager via WMI in order to check all possible locations.

#Adapted from https://gist.github.com/altrive/5329377
#Based on <http://gallery.technet.microsoft.com/scriptcenter/Get-PendingReboot-Query-bdb79542>
function Test-PendingReboot {
    if (Get-ChildItem "HKLM:\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending" -EA Ignore) { return $true }
    if (Get-Item "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired" -EA Ignore) { return $true }
    if (Get-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager" -Name PendingFileRenameOperations -EA Ignore) { return $true }
    try { 
        $util = [wmiclass]"\\.\root\ccm\clientsdk:CCM_ClientUtilities"
        $status = $util.DetermineIfRebootPending()
        if (($status -ne $null) -and $status.RebootPending) {
            return $true
        }
    }
    catch { }

    return $false
}

Test-PendingReboot

这篇关于如何检查挂起的重启?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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