2017-04-24 213 views

回答

0

使用PowerShell

如果你試圖確定哪個服務器需要重新啓動的,你一定會喜歡這個PowerShell腳本以檢查其狀態。事實證明,識別待重啓服務器的簡單方法是檢查註冊表。此信息存儲在註冊表的HKeyLocalMachine配置單元中。 PowerShell誕生並與註冊表配合使用。註冊表是內置的PowerShell提供程序之一。甚至已經有一個PSDrive連接到該註冊表配置單元!就像文件系統一樣,您可以瀏覽註冊表。

更改爲註冊表驅動器。

//設置地點也可以通過它的別名調用 - CD和SL

設置地點HKLM:

//獲取-ChildItem也可以通過它的別名調用 - 迪爾和LS

獲取-ChildItem

哇!超級簡單,對嗎? 現在你只需要知道「掛起重啓」位置在哪裏。有幾個地方要檢查。

HKLM \ SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ WindowsUpdate \ Auto Update \ RebootRequired 通過自動更新安裝的修補程序是否需要重新引導。

HKLM \ SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Component Based Servicing \ RebootPending 是另一個可以識別掛起重新啓動的地方。

HKLM \ SYSTEM \ CurrentControlSet \ Control \ Session Manager 還有一個。最後,還有配置管理器,如果有,可以通過WMI查詢。

我發現我真的很喜歡檢查所有四個位置的功能。我需要用一些參數來包裝它來檢查遠程計算機,但總的來說這是一個很好的開始。我已經調整函數在滿足的第一個條件上返回$ true,因爲我只關心計算機是否正在等待重新啓動,而不是重新啓動源的來源。基於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 }

https://gist.github.com/altrive/5329377

改編

相關問題