2017-12-18 302 views
-1

我想知道Windows機器需要重啓或不重啓。但是,我的腳本正在投擲和錯誤。如何檢查掛起的重新啓動?

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 

我在「命令提示符」中運行此命令。不知道這意味着什麼!

+0

嘿得到的答案 的PowerShell 「(調用-WmiMethod - 命名根\ CCM \ clientsdk -Class CCM_ClientUtilities -Name DetermineIfRebootPending).RebootPending」 –

+1

這是完全可以接受的回答你自己的問題,甚至接受它。考慮添加你的評論作爲一個正確的答案 - 它可能會在未來幫助其他人。 – David

+0

[C#:如何可以檢測到Windows 7需要重新啓動]可能重複(https://stackoverflow.com/questions/15482174/c-how-can-a-required-reboot-be-detected-for-windows -7) – TheIncorrigible1

回答

2

基本上,你可以使用Test-Path,因爲只有在掛起重啓時才存在該密鑰。

Test-Path "HKLM:\SOFTWARE­\Microsoft­\Windows­\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired" 
1

有幾件事情:

  1. 你的語法不,如果你想從運行CMD PowerShell命令正確,它看起來像這樣:

    powershell.exe「GET-項目'HKLM:SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ WindowsUpdate \ Auto Update \ RebootRequired'「

  2. 至少對我來說,不存在一個名爲」RebootRequired「的Item/Key,我只獲得有效的Output下一個更高的路徑Get-Item "HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update它提供了鍵和值保存在註冊表項中,但沒有密鑰「RebootRequired」,你確定這個密鑰存在嗎?

  3. 如果你發現一個問題的答案,請張貼的答案,而不是你自己的意見,但它似乎並沒有在我的機器上工作...

+1

第3位。應該是問題中的評論。這不是答案的一部分。 – Matt