ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    PowerShell: Function to test for pending reboot reason

    Scheduled Pinned Locked Moved IT Discussion
    2 Posts 2 Posters 304 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • PhlipElderP
      PhlipElder
      last edited by

      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
      
      1 Reply Last reply Reply Quote 2
      • ObsolesceO
        Obsolesce
        last edited by

        This reminded me of a tweet I seennot so long ago:
        https://twitter.com/MarkWilkinsonNZ/status/1155931194925522944?s=19

        It leads to here: https://adamtheautomator.com/pending-reboot-registry-windows/

        1 Reply Last reply Reply Quote 1
        • 1 / 1
        • First post
          Last post