Skip to main content

Reboot Pending Prompt - Detection [Windows]

Overview​

This script serves as the detection logic for the Reboot Pending Prompt solution. Its primary function is to intelligently decide whether a reboot prompt should be displayed to the user.

It performs checks in four key areas:

  1. Operational Safety: Before evaluating necessity, the script checks if the Reboot Pending prompt - Autofix is currently active (specifically checking for the scheduled tasks it manages). If a prompt cycle is already in progress, this script exits immediately to prevent conflicting or duplicate actions.
  2. Scheduled Restart Awareness: If the user has already picked their own restart time through the optional reboot scheduler, that commitment takes priority over everything below. The device is left alone until the restart is nearly due, at which point this script triggers the Autofix so the reminder can be shown. See Scheduled Reboot Handling.
  3. Necessity: It determines if a reboot is actually required by checking Windows Registry keys (for pending updates), comparing system uptime against a configured threshold, or checking for a manual administrator override.
  4. Timing & Convenience: If a reboot is needed, the script then validates if the current moment is appropriate for a prompt. It checks constraints such as "Quiet Hours" (suppress windows), weekend exclusions, user presence (logged in vs. lock screen), and ensures the user isn't prompted too frequently.

If the script determines a reboot is needed, the timing is valid, and no conflicting prompts are active, it returns an exit code that triggers the remediation script.

Install-In-Progress Protection​

Before allowing any unattended reboot (no user logged in, or locked screen with the missed prompt threshold reached), the script checks whether the machine is currently installing software or updates. If it detects an active install, it skips the reboot and exits cleanly. The next time the script runs, it checks again. Once the install finishes, the reboot proceeds normally.

This prevents the machine from restarting in the middle of a Windows Update, application installer, or feature upgrade.

The script looks for the following signals:

SignalWhat It Means
TiWorker.exeWindows Update is actively installing an update
wusa.exeA standalone Windows Update package is being installed
SetupHost.exeA Windows Feature Update is in progress
MoUsoCoreWorker.exeThe Windows Update orchestrator is doing background work
Windows10Upgrader.exeA feature upgrade using the Windows Update Agent is running
winget.exe (active)Windows Package Manager is installing or updating software (only when actively using CPU)
MSI mutex heldAn MSI installer package is currently running

Note: This check only applies to unattended reboots. If a user is at their desk and clicks "Yes" to reboot, the reboot happens immediately regardless of background installs. The user made a conscious choice.

Scheduled Reboot Handling​

When the optional reboot scheduler is enabled (see cPVAL Reboot Schedule Max Hours), the user is allowed to pick their own restart time on the final prompt. This script is what honours that choice.

Before it evaluates whether a reboot is needed at all, it inspects the two tracking fields the Autofix maintains:

Field StateWhat This Script Does
cPVAL Scheduled Reboot Time holds a future time, further out than the reminder windowNothing. The device is deliberately not detected while it waits for the restart the user already agreed to.
cPVAL Scheduled Reboot Time is now within cPVAL Reboot Reminder Lead Minutes, or is already overdueTriggers the Autofix so it can display the pre-reboot reminder and hand the countdown to the operating system.
cPVAL Reboot Reminder Sent Time is set and the device has restarted sinceClears every tracking field. The cycle is complete.
cPVAL Reboot Reminder Sent Time is set and the countdown is still runningNothing. A restart is already pending, so a second reminder must not be fired into it.
cPVAL Reboot Reminder Sent Time is set but 60 minutes have passed with no restartTreats the countdown as cancelled, clears the stale values, and resumes the normal prompt cycle.
Either field holds a value that cannot be readClears it and resumes the normal prompt cycle.

A device that was switched off or asleep through its scheduled time arrives here overdue, which still triggers the Autofix. The restart therefore happens late rather than never.

⚠️ Important: cPVAL Reboot Reminder Lead Minutes must be set to the same value on both this Detection automation and the Autofix automation. This script uses it to decide when a scheduled restart is due for its reminder, and the Autofix uses it to size the countdown. Keep the value well below 60 minutes, or a restart that is still legitimately pending will be treated as cancelled.

Sample Run​

Note: This script is specifically engineered to operate as the detection condition within the Reboot Pending Prompt - Windows Workstation compound condition. Manual execution is not recommended, as the script's output is intended to trigger automated remediation actions rather than provide direct feedback.

Dependencies​

Custom Fields​

Custom FieldTypeExampleScopeAvailable OptionsEditableDescription
cPVAL Pending RebootCheckboxTrueDeviceTrue, FalseYesManually forces a reboot prompt cycle on this specific device, regardless of Windows update status.
cPVAL Last PromptedText2024-05-20 14:30:00DeviceN/ANoAutomatically records the date and time of the last reboot prompt shown to the user.
cPVAL Times PromptedNumeric2DeviceN/ANoAutomatically tracks how many times the user has been prompted (and deferred) for a reboot.
cPVAL Reboot Prompt When Pending RebootDropdownEnableOrganization, Location, DeviceEnable, DisableYesEnables or disables reboot prompts triggered specifically by Windows Registry pending reboot flags.
cPVAL Reboot Prompt Uptime DaysNumeric14Organization, Location, DeviceN/AYesSets the maximum number of days a machine can run without a reboot before a prompt is triggered. Set to 0 to disable.
cPVAL Reboot Prompt CountNumeric4Organization, Location, DeviceN/AYesDefines how many times a user can defer the reboot before it becomes mandatory.
cPVAL Reboot Prompt Duration Between PromptNumeric4Organization, Location, DeviceN/AYesSpecifies the waiting period (in hours) between consecutive reboot prompts to avoid spamming the user.
cPVAL Reboot Prompt Skip WeekendsDropdownEnableOrganization, Location, DeviceEnable, DisableYesPrevents reboot prompts from appearing on Saturdays and Sundays.
cPVAL Reboot Prompt Suppress Time WindowText1800-0800Organization, Location, DeviceN/AYesDefines a 24-hour time range (HHmm-HHmm) during which no prompts will be shown (e.g., overnight quiet hours).
cPVAL Reboot if Not Logged InDropdownEnableOrganization, Location, DeviceEnable, DisableYesAllows the system to reboot immediately without showing a prompt if no user is currently signed in.
cPVAL Reboot During Suppress PeriodDropdownEnableOrganization, Location, DeviceEnable, DisableYesPermits unattended or forced reboots to proceed even during configured suppress windows or weekends.
cPVAL Max Missed Prompts Before ForceNumeric3Organization, Location, DeviceN/AYesSets the number of consecutive missed prompts (due to locked screen or no user) before forcing a reboot. Set to 0 to disable.
cPVAL Consecutive Missed PromptsNumeric2DeviceN/ANoAutomatically tracks how many prompt cycles were missed because the screen was locked or no user was signed in.
cPVAL First Missed Prompt TimeText2024-05-20 14:30:00DeviceN/ANoAutomatically records the exact date and time the current streak of missed prompts began.
cPVAL Reboot Reminder Lead MinutesNumeric15Organization, Location, DeviceN/AYesHow many minutes ahead of a scheduled restart the pre-reboot reminder becomes due. Must match the value used by the Autofix.
cPVAL Scheduled Reboot TimeText2026-09-09 14:30:00DeviceN/ANoThe restart time the user selected on the final prompt. While this holds a future time, the device is not detected. Managed automatically.
cPVAL Reboot Reminder Sent TimeText2026-09-09 14:15:00DeviceN/ANoRecords when the reminder was sent and the restart countdown began. A value here means a restart is already pending. Managed automatically.

Configuration Hierarchy​

The solution evaluates settings using a strict top-down hierarchy. If a value is configured at a higher priority level, it overrides the lower levels.

PriorityLevelDescription
1 (Highest)Device Level Custom FieldOverrides all lower levels. Applied to a specific endpoint.
2Location Level Custom FieldOverrides Organization level. Applied to all endpoints in a location.
3Organization Level Custom FieldGlobal default for the entire tenant.
4 (Lowest)Script Runtime VariableUltimate fallback default used if the custom field is blank at all levels.

Script Variables​

Instead of hardcoding defaults, the script relies on NinjaRMM Script Variables as the ultimate fallback mechanism. You can configure these variables directly in the script's settings within NinjaRMM to establish global baseline behaviors without modifying the code-signed script file.

NameTypeExampleDefaultAvailable OptionsDescription
Prompt CountInteger54N/AMax number of prompts allowed before the cycle resets.
Duration Between PromptsInteger64N/AMinimum hours to wait between prompts.
Suppress Time WindowString/Text1800-0800(blank)N/A24h time range (HHmm-HHmm) to suppress prompts.
Max Missed Prompts Before ForceInteger30N/ANumber of consecutive missed prompts before forcing a reboot. Set to 0 to disable.
Reboot If Not Logged InDropdownEnableDisableDisable, EnableEnable to reboot immediately if no user is signed in.
Skip WeekendsDropdownEnableDisableDisable, EnableEnable to suppress prompts on Sat/Sun.
Reboot During Suppress PeriodDropdownEnableDisableDisable, EnableFallback default. Allows unattended machines to reboot during suppress windows or weekends if auto-reboot is enabled or the missed prompt threshold is reached.
Reboot Reminder Lead MinutesInteger1515N/AHow many minutes ahead of a scheduled restart the reminder becomes due. Only used when the reboot scheduler is enabled. Must match the Autofix value.

💡 Note: Do not attempt to change default values by editing the script file directly. The PowerShell script is code-signed, and modifying the code will break the signature and prevent execution. Always use Custom Fields or Script Variables to adjust behaviors.

Automation Setup/Import​

Automation Configuration

Output​

  • Activity Details: Text output indicating if a reboot is required and if conditions were met.
  • Custom Fields: Updates cPVAL Pending Reboot, cPVAL Last Prompted, cPVAL Times Prompted, cPVAL Consecutive Missed Prompts, and cPVAL First Missed Prompt Time as part of reset and missed-prompt tracking. Clears cPVAL Scheduled Reboot Time and cPVAL Reboot Reminder Sent Time once a scheduled restart completes, or when either value goes stale.

Changelog​

2026-09-09​

  • Added support for the optional reboot scheduler. A device with a restart the user has already scheduled is no longer detected while it waits, and is instead detected once that restart comes due for its reminder.
  • Added the new custom fields cPVAL Reboot Reminder Lead Minutes, cPVAL Scheduled Reboot Time, and cPVAL Reboot Reminder Sent Time.
  • Added the new script variable Reboot Reminder Lead Minutes.
  • A restart countdown that is still pending after 60 minutes is now treated as cancelled, so a device whose shutdown was aborted returns to the normal prompt cycle on its own.
  • The tracking fields for the scheduler are cleared everywhere the existing tracking fields are cleared, including the self-healing reset.

2026-07-20​

  • Added the new custom field cPVAL Reboot During Suppress Period to allow unattended or forced reboots to proceed during configured suppress windows or weekends.
  • Converted hardcoded default values to NinjaRMM Script Variables, allowing administrators to define global fallback defaults directly within the script configuration UI.
  • Removed the BITS transfer job check from the Install-In-Progress guard to prevent false positives from regular background downloads (e.g., browser downloads, non-critical updates).

2026-06-10​

  • Missed prompt counter now uses real elapsed time instead of counting each script run. This makes the forced reboot timeline predictable no matter how often the detection script checks in.
  • Added safety checks for active installations before rebooting unattended machines. The script now looks for Windows Updates, feature upgrades, MSI installers, and winget activity.
  • If a forced reboot is due but an install is still running, the reboot waits until the install finishes. It will trigger automatically on the next check after the install completes.
  • Machines with no user logged in will no longer reboot mid-update. The script exits safely and retries on the next cycle once servicing is done.
  • Winget (Windows Package Manager) is only treated as active when it is actually doing work, preventing false detections from an idle process.
  • Script documentation updated to reflect all of the above changes.

2026-06-03​

  • Added support for missed-prompt tracking custom fields.
  • Added default values for missed-prompt handling, weekend behavior, suppress window behavior, and no-user reboot behavior.

2026-05-26​

  • Added a default values region in the PowerShell script.
  • Fixed a bug where the script was failing to reset the custom fields for manual reboot after rejecting the first prompt.

2026-03-23​

  • Updated .Net8 Desktop Runtime installation logic to install the latest available version.
  • Code Signed the PowerShell script.

2025-12-19​

  • Initial version of the document