DevOps | Scripts | Automation

PowershellWindows Server

How to detect if a server reboot is pending?

Overview

Sometimes, we receive a notification that your Windows operating system requires a reboot. This can present several challenges, such as the inability to perform tasks like file renaming and application installation.

In corporate production systems, it is risky for a virtual machine (VM) to be rebooted without prior notification, as this can result in an outage of enterprise applications. Fortunately, there are several tools available that can detect pending reboots of servers.

However, system admins can utilize the automation scripts which help them to detect pending reboots on the VM. For the Windows OS, there are three registries that detect if the reboot is pending.

At the end of the article, PowerShell and Python scripts are mentioned to detect pending reboots.

Detect pending Reboot server using Registry

There are three registry locations in Windows where you can determine if the VM has the pending reboot if those registry entries are present.

  • The RebootPending value at
HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing
  • The RebootRequired value at
HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update
  • The PendingFileRenameOperations value at
HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager

Currently, we have three registries that identify pending required reboots. Let’s utilize PowerShell to determine how we can identify these registries.

Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing' -Name RebootPending -ErrorAction Ignore

Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update' -Name RebootRequired -ErrorAction Ignore

Get-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager' -Name PendingFileRenameOperations -ErrorAction Ignore

If any output value holds then it shows that the reboot is pending for the particular server.

GitHub PowerShell script:

The combined command output script for the Powershell can be downloaded from the below GitHub repository.

https://github.com/chiragce17/MyPublicRepo/blob/main/PowerShell/WindowsAdminTools/Get-PendingReboot.ps1

GitHub Python Script:

https://github.com/chiragce17/MyPublicRepo/blob/main/Python/WindowsUtility/Check-PendingReboot.py

Loading