Skip to content

Instantly share code, notes, and snippets.

@risadams
Created February 19, 2024 15:35
Show Gist options
  • Save risadams/44788c8d21b3abec0cd180b6c8d0c442 to your computer and use it in GitHub Desktop.
Save risadams/44788c8d21b3abec0cd180b6c8d0c442 to your computer and use it in GitHub Desktop.
# 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