PowerShell: Function to test for pending reboot reason



  • function Test-PendingReboot
    {
     if (Get-ChildItem "HKLM:\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending" -EA Ignore) { 
     $reboot = 'Component Based Servicing\RebootPending'
     Write-Host $reboot  }
     if (Get-Item "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired" -EA Ignore) { 
     $reboot = 'WindowsUpdate\Auto Update\RebootRequired' 
     Write-Host $reboot }
     if (Get-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager" -Name PendingFileRenameOperations -EA Ignore) { 
       $reboot = 'CurrentControlSet\Control\Session Manager' 
       Write-Host $reboot}
     try { 
       $util = [wmiclass]"\\.\root\ccm\clientsdk:CCM_ClientUtilities"
       $status = $util.DetermineIfRebootPending()
       if(($status -ne $null) -and $status.RebootPending){
         $reboot = 'Configuration Manager'
         $reboot
       }
     }catch{}
     
     $reboot = 'no reboot required'
     Write-Host $reboot
    }
    
    Test-PendingReboot
    



Log in to reply