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