2023-03-31 15:56:07 +00:00
#Function to check if there is a Pending Reboot
2022-07-30 01:48:37 +00:00
function Test-PendingReboot {
2022-10-26 22:49:10 +00:00
2022-07-30 01:48:37 +00:00
$Computer = $env:COMPUTERNAME
$PendingReboot = $false
2022-10-26 22:49:10 +00:00
2022-07-30 01:48:37 +00:00
$HKLM = [ UInt32 ] " 0x80000002 "
$WMI_Reg = [ WMIClass ] " \\ $Computer \root\default:StdRegProv "
2022-10-26 22:49:10 +00:00
2022-07-30 01:48:37 +00:00
if ( $WMI_Reg ) {
2022-10-18 13:23:39 +00:00
if ( ( $WMI_Reg . EnumKey ( $HKLM , " SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\ " ) ) . sNames -contains 'RebootPending' ) { $PendingReboot = $true }
if ( ( $WMI_Reg . EnumKey ( $HKLM , " SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\ " ) ) . sNames -contains 'RebootRequired' ) { $PendingReboot = $true }
2022-10-26 22:49:10 +00:00
2022-07-30 01:48:37 +00:00
#Checking for SCCM namespace
$SCCM_Namespace = Get-WmiObject -Namespace ROOT \ CCM \ ClientSDK -List -ComputerName $Computer -ErrorAction Ignore
if ( $SCCM_Namespace ) {
2022-10-18 13:23:39 +00:00
if ( ( [ WmiClass ] " \\ $Computer \ROOT\CCM\ClientSDK:CCM_ClientUtilities " ) . DetermineIfRebootPending ( ) . RebootPending -eq $true ) { $PendingReboot = $true }
2022-07-30 01:48:37 +00:00
}
2022-10-26 22:49:10 +00:00
2022-07-30 01:48:37 +00:00
}
return $PendingReboot
2022-07-30 13:10:41 +00:00
}