Checks all four places Windows records a pending restart: Component Based Servicing, Windows Update, pending file rename operations and a pending computer rename. It reports the reason rather than a bare yes or no, and hands RebootPending or NoRebootPending to the next runbook step so a managed reboot can run only where it is actually needed.
powershell
# Check Pending Reboot
# Single use case: report whether the server requires a restart and why
#-----------------------------------------------------------------
function Write-Log {
param($Message)
Write-Host "<WRITE-LOG = `"*$Message*`">"
}
$reasons = @()
if (Test-Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending") {
$reasons += "Component Based Servicing (Windows features/updates)"
}
if (Test-Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired") {
$reasons += "Windows Update"
}
$pfro = Get-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager" -Name PendingFileRenameOperations -ErrorAction SilentlyContinue
if ($pfro -and $pfro.PendingFileRenameOperations) {
$reasons += "Pending file rename operations"
}
$computerRename = Get-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName" -ErrorAction SilentlyContinue
$pendingRename = Get-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName" -ErrorAction SilentlyContinue
if ($computerRename -and $pendingRename -and ($computerRename.ComputerName -ne $pendingRename.ComputerName)) {
$reasons += "Computer rename pending"
}
if ($reasons.Count -eq 0) {
Write-Log "No reboot pending - system is clean."
$store = "NoRebootPending"
} else {
Write-Log "REBOOT PENDING! Reasons:"
foreach ($r in $reasons) { Write-Log " - $r" }
# Next runbook script can react (ex. 02-SE-ManagedReboot.ps1)
$store = "RebootPending"
}Run it across your fleet
This script runs as-is on a single host. Paste it into ServerEngine to schedule it, run it on a whole server group in parallel, and keep the credentials out of the file — see the scripts documentation and the credential store.
More in Checks & Diagnostics
Ready when you are.
Try ServerEngine free for 7 days.