Usually, after a user installs a driver, an update (software or system) , or software, or makes some configuration changes on a Windows client or server machine, the user will be prompted to reboot the system. In this post, we will walk you through the steps on how to check for Pending Reboot on a Windows computer.
How to check for Pending Reboot on a Windows computer
On completion of many Windows OS tasks, sometimes the computer is forced to require a reboot. While logged in and in an active session, you will be notified that a reboot is pending or required by some popup box or notification — which you can either dismiss or accept to restart Windows. But, in some situations whereby you do not want or can’t immediately reboot the machine — for example, you have some unfinished work you need to complete before you restart, or you’ve just installed updates on a production server and that server can’t be rebooted right away.
In scenarios like this, especially as it concerns the latter, you may forget about the reboot and at a later time realize that some servers or client machines need to be rebooted but you are now unable to identify which of the machines — in this situation, you can be able to check for Pending Reboot on Windows computer using a PowerShell script.
Now, when a reboot is pending, Windows will add some registry values or flags to indicate so at the following registry location with the associated values and conditions as shown in the table below.
Key | Value | Condition |
HKLM:\SOFTWARE\Microsoft\Updates | UpdateExeVolatile | Value is anything other than 0 |
HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager | PendingFileRenameOperations | value exists |
HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager | PendingFileRenameOperations2 | value exists |
HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired | NA | key exists |
HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Services\Pending | NA | Any GUID subkeys exist |
HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\PostRebootReporting | NA | key exists |
HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce | DVDRebootSignal | value exists |
HKLM:\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending | NA | key exists |
HKLM:\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootInProgress | NA | key exists |
HKLM:\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing\PackagesPending | NA | key exists |
HKLM:\SOFTWARE\Microsoft\ServerManager\CurrentRebootAttempts | NA | key exists |
HKLM:\SYSTEM\CurrentControlSet\Services\Netlogon | JoinDomain | value exists |
HKLM:\SYSTEM\CurrentControlSet\Services\Netlogon | AvoidSpnSet | value exists |
HKLM:\SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName | ComputerName | Value ComputerName in HKLM:\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName is different |
As we have identified the relevant registry paths, instead of manually combing through the registry because you may forget to check one registry path or just forget which ones to check, you can create and run a Check-PendingReboot.ps1 script using the code below to automate the task to check all of the registry keys in the table above.
[CmdletBinding()] param( [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [string[]]$ComputerName, [Parameter()] [ValidateNotNullOrEmpty()] [pscredential]$Credential )
$ErrorActionPreference = 'Stop'
$scriptBlock = {
$VerbosePreference = $using:VerbosePreference function Test-RegistryKey { [OutputType('bool')] [CmdletBinding()] param ( [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [string]$Key ) $ErrorActionPreference = 'Stop'
if (Get-Item -Path $Key -ErrorAction Ignore) { $true } }
function Test-RegistryValue { [OutputType('bool')] [CmdletBinding()] param ( [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [string]$Key,
[Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [string]$Value ) $ErrorActionPreference = 'Stop'
if (Get-ItemProperty -Path $Key -Name $Value -ErrorAction Ignore) { $true } }
function Test-RegistryValueNotNull { [OutputType('bool')] [CmdletBinding()] param ( [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [string]$Key,
[Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [string]$Value ) $ErrorActionPreference = 'Stop'
if (($regVal = Get-ItemProperty -Path $Key -Name $Value -ErrorAction Ignore) -and $regVal.($Value)) { $true } }
# Added "test-path" to each test that did not leverage a custom function from above since # an exception is thrown when Get-ItemProperty or Get-ChildItem are passed a nonexistant key path $tests = @( { Test-RegistryKey -Key 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending' } { Test-RegistryKey -Key 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootInProgress' } { Test-RegistryKey -Key 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired' } { Test-RegistryKey -Key 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing\PackagesPending' } { Test-RegistryKey -Key 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\PostRebootReporting' } { Test-RegistryValueNotNull -Key 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager' -Value 'PendingFileRenameOperations' } { Test-RegistryValueNotNull -Key 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager' -Value 'PendingFileRenameOperations2' } { # Added test to check first if key exists, using "ErrorAction ignore" will incorrectly return $true 'HKLM:\SOFTWARE\Microsoft\Updates' | Where-Object { test-path $_ -PathType Container } | ForEach-Object { (Get-ItemProperty -Path $_ -Name 'UpdateExeVolatile' | Select-Object -ExpandProperty UpdateExeVolatile) -ne 0 } } { Test-RegistryValue -Key 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce' -Value 'DVDRebootSignal' } { Test-RegistryKey -Key 'HKLM:\SOFTWARE\Microsoft\ServerManager\CurrentRebootAttemps' } { Test-RegistryValue -Key 'HKLM:\SYSTEM\CurrentControlSet\Services\Netlogon' -Value 'JoinDomain' } { Test-RegistryValue -Key 'HKLM:\SYSTEM\CurrentControlSet\Services\Netlogon' -Value 'AvoidSpnSet' } { # Added test to check first if keys exists, if not each group will return $Null # May need to evaluate what it means if one or both of these keys do not exist ( 'HKLM:\SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName' | Where-Object { test-path $_ } | %{ (Get-ItemProperty -Path $_ ).ComputerName } ) -ne ( 'HKLM:\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName' | Where-Object { Test-Path $_ } | %{ (Get-ItemProperty -Path $_ ).ComputerName } ) } { # Added test to check first if key exists 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Services\Pending' | Where-Object { (Test-Path $_) -and (Get-ChildItem -Path $_) } | ForEach-Object { $true } } )
foreach ($test in $tests) { Write-Verbose "Running scriptblock: [$($test.ToString())]" if (& $test) { $true break } } }
foreach ($computer in $ComputerName) { try { $connParams = @{ 'ComputerName' = $computer } if ($PSBoundParameters.ContainsKey('Credential')) { $connParams.Credential = $Credential }
$output = @{ ComputerName = $computer IsPendingReboot = $false }
$psRemotingSession = New-PSSession @connParams if (-not ($output.IsPendingReboot = Invoke-Command -Session $psRemotingSession -ScriptBlock $scriptBlock)) { $output.IsPendingReboot = $false } [pscustomobject]$output } catch { Write-Error -Message $_.Exception.Message } finally { if (Get-Variable -Name 'psRemotingSession' -ErrorAction Ignore) { $psRemotingSession | Remove-PSSession } } }
You can provide as many servers as you want via the ComputerName parameter in the script which will return True or False along with the server name. You can execute the script similar to the following and make sure PowerShell Remoting is set up and available on your servers.
PS51> .\Test-PendingReboot.ps1 -Server SRV1,SRV2,SRV3,etc
Read: How to schedule PowerShell script in Task Scheduler
By using the PowerShell script, you can query one or all computers in the domain or manually provide the server names to determine the machines pending a reboot. Once identified, you can then reboot the machines right away or make a list to reboot later.
Now read: How to Remotely Restart Windows computer using PowerShell
What does it mean a Windows reboot is pending?
Generally, a pending reboot request occurs when a program or installation makes a change to files, registry keys, services, or operating system settings potentially leaving the system in a transient state. In the case you get the A pending reboot has been detected notification, it simply indicates that updates are pending on the machine and a reboot must be performed before any additional updates can be installed.
Read:
- How to Disable or Enable Update Restart Notification
- Windows Update Pending install or download, Initializing, etc
How to check pending reboots in the registry?
You can do this by searching the Windows Registry for the RebootRequired key. In the table above in this post, we have identified the relevant registry location for pending reboot registry keys. If you want to show a notification when your PC requires a restart to complete a Windows update installation, click Start > Settings > Update & security > Windows Updates > Advanced Options. Toggle the button to on or off for the Show a notification when your PC requires a restart to finish updating option.
Also read: There is a system repair pending which requires a reboot to complete.