Created
February 19, 2024 15:35
-
-
Save risadams/44788c8d21b3abec0cd180b6c8d0c442 to your computer and use it in GitHub Desktop.
This file contains 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
# PowerShell | |
function Test-PendingReboot | |
{ | |
$svc = "HKLM:\Software\Microsoft\Windows\CurrentVersion\" ` | |
+ "Component Based Servicing\RebootPending"; | |
$wupd = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\" ` | |
+ "WindowsUpdate\Auto Update\RebootRequired" | |
$file = "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager"; | |
$reasons = 0; | |
if (Get-ChildItem $svc -EA Ignore) | |
{ $reasons += 1; } | |
if (Get-Item $wupd -EA Ignore) | |
{ $reasons += 2; } | |
if (Get-ItemProperty $file -Name PendingFileRenameOperations -EA Ignore) | |
{ $reasons += 4; } | |
try | |
{ | |
$util = [wmiclass]"\\.\root\ccm\clientsdk:CCM_ClientUtilities" | |
$status = $util.DetermineIfRebootPending() | |
if(($status -ne $null) -and $status.RebootPending) | |
{ | |
$reasons += 8; | |
} | |
}catch{} | |
return $reasons; | |
} | |
Test-PendingReboot; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment