Created
July 17, 2018 19:17
-
-
Save johnrizzo1/c49bbd139cbc8a9e54b61f32a29fd2a0 to your computer and use it in GitHub Desktop.
Check if a windows server needs a reboot with powershell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# I found the following useful snippet here | |
# http://ilovepowershell.com/2015/09/10/how-to-check-if-a-server-needs-a-reboot/ | |
#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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment