Problem overview.
The challenge this resource is designed to solve.
Unrecognized pending restarts can compromise system stability and security, as critical updates or configuration changes remain incomplete. This script reduces the chance of oversight by detecting any signs that a reboot is required, helping IT Professionals and MSPs maintain reliable, up-to-date Windows environments.
About this resource.
What it does and how it fits into your workflow.
This PowerShell script scans multiple registry paths commonly associated with pending reboots, such as those triggered by Windows Updates, file renames, and system name changes. If it encounters any indicators suggesting a reboot is required, it prints an alert for easy visibility.
You can integrate it into a script-based monitor within Level to receive real-time notifications when a reboot is pending. Alternatively, set up a schedule in Level’s Automation to check regularly and ensure your machines are kept in an optimal state, avoiding stale updates and preventing unexpected downtime.
<#
This resource is provided as a convenience for Level users. We cannot
guarantee it will work in all environments. Please test before deploying
to your production environment. We welcome contributions to our community
library
Level Library
https://level.io/library/script-windows-monitor-restart-required
#>
function Get-PendingRebootStatus {
$rebootRequired = $false
# 1. Windows Update Agent (best signal)
try {
$sysInfo = New-Object -ComObject "Microsoft.Update.SystemInfo"
if ($sysInfo.RebootRequired) {
return $true
}
} catch {
# COM not available; continue with others
}
# 2. Component Based Servicing
if (Test-Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending') {
return $true
}
# 3. Windows Update's own reboot-required flag
if (Test-Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired') {
return $true
}
# 4. Pending file operations (drivers, installers, AV)
try {
$pendingOps = (Get-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager' -ErrorAction SilentlyContinue).PendingFileRenameOperations
if ($pendingOps) {
return $true
}
} catch {}
# 5. Computer rename pending
try {
$active = (Get-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName').ComputerName
$pending = (Get-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName').ComputerName
if ($active -ne $pending) {
return $true
}
} catch {}
return $rebootRequired
}
if (Get-PendingRebootStatus) {
Write-Output "ALERT: Reboot Required"
} else {
Write-Output "No reboot is required."
}Use cases.
Common ways to put this resource to work.
- Monitoring servers after monthly Patch Tuesday updates
- Detecting incomplete software installations or migrations
- Confirming reboots after automated tasks or maintenance windows
- Verifying pending restarts during large-scale workstation deployments
Recommendations.
Practical guidance for a reliable rollout.
- Test in a safe environment before deploying widely
- Use a script-based monitor in Level for on-demand checks when updates are installed
- Automate regular scans with Level’s scheduling options
- Pair with a remediation script or manual reboot plan for systems flagged as needing a restart
- Monitor output logs to confirm each system’s status after updates or changes