Skip to main content

Uptime Reboot Policy with NinjaOne and PowerShell

· 4 min read

Long-running uptime can be useful, but it also increases risk: pending updates remain pending, patch windows get missed, and users eventually get hit with inconvenient restarts.

This script gives you a practical middle ground:

  • Detect when uptime exceeds a threshold
  • Notify the logged-in user with a Windows toast
  • Optionally let the user schedule an earlier reboot
  • Enforce a reboot deadline with a Scheduled Task
  • Write policy state and user action back to NinjaOne custom fields

Creating Fields

Creating custom fields in NinjaOne
To create a custom field in NinjaOne go to Administration > Devices and select either Role Custom Fields or Global Custom Fields then select Add.

  • Role Custom Fields are custom fields that are specific to a device role.
  • Global Custom Fields are custom fields that are applicable to all devices and/or to a location and/or organisation
Make sure you add the fields to the roles you want to use them in at Administration > Devices > Roles (for role custom fields).

When you create your custom field you need to make sure that you set the Scripts permission to ensure that you can read or write to the field from your scripts - as appropriate for the script you're using.

This script can run without custom fields, but adding them gives you much better visibility for reporting and follow-up.

Field LabelField NameField TypeDescription
Last Uptime Reboot PromptlastUptimeRebootPromptDate/TimeWhen the user was last prompted.
Last Uptime Prompt ActionlastUptimePromptUserActionDropdownLast recorded user action (Rebooted, Scheduled Reboot, Ignored).
Last Uptime Reboot DeadlinelastUptimeRebootDeadlineDate/TimeCurrent enforced reboot deadline from the script.
Uptime Reboot Policy StateuptimeRebootPolicyStateDropdownCurrent policy state (Below Threshold, Threshold Exceeded, Prompt Shown, Deadline Scheduled, Cleanup Completed).

Uptime policy custom field definitions in NinjaOne

The Script

UptimeRebootPolicy.ps1
loading...

Script run configuration in NinjaOne

Script Variables

The script has sensible defaults, but these are the key variables to expose in NinjaOne for full control.

Ninja Variable NameTypeDefaultWhat it does
thresholdDaysInteger7Uptime threshold before action starts.
toastTitleStringRestart RecommendedToast title shown to the user.
toastMessagePrefixStringThis device has been online for longer than the recommended uptime window.Prefix used in the toast body.
rebootDeadlineHoursInteger24Maximum hours before forced reboot.
enforceRebootDeadlineCheckboxtrueEnables scheduled task enforcement.
allowInteractiveSchedulingCheckboxtrueAllows end-user to choose an earlier reboot.
useRunAsUserForUserExperienceCheckboxtrueUses RunAsUser when script runs as SYSTEM.
bypassDoNotDisturbCheckboxtrueUses an alarm-style toast scenario to surface notifications.
interactivePromptTimeoutSecondsInteger120Auto-close timeout for the interactive prompt UI.
brandNameStringIT SupportBranding header in the prompt UI.
brandSupportTextStringNeed help? Contact your IT Service Desk.Support message in the prompt UI.
brandSupportLabelsString CSVPortal,Email,PhoneLabels for support options.
brandSupportLinksString CSV,,Matching links/targets for support options.
brandAccentHexString0063B1Accent color used in UI.
rebootTaskNameStringUptime-Reboot-DeadlineScheduled task name used for enforcement.
runModeDropdownAutoAuto for normal behavior, CleanupOnly to remove task and exit.
cleanupWhenBelowThresholdCheckboxtrueRemoves reboot task when uptime is below threshold.
logEffectiveConfigurationCheckboxtrueLogs resolved settings to output.
dryRunCheckboxfalseSimulates actions without changing anything.

Script variable definitions in NinjaOne

How It Works

  1. Reads last boot time from Win32_OperatingSystem and calculates uptime.
  2. If uptime is below threshold, it writes Below Threshold and optionally removes any existing reboot task.
  3. If uptime is above threshold, it writes Threshold Exceeded, schedules an enforced reboot deadline, and attempts user interaction.
  4. If interactive UX is available, the user can:
    • reboot in about 2 minutes
    • schedule an earlier reboot in X hours
    • keep the default deadline
  5. Displays a toast showing uptime and reboot deadline details.
  6. Writes action/policy fields back to NinjaOne for reporting and monitor logic.

Interactive reboot scheduling prompt shown to users

Toast notification shown when uptime threshold is exceeded

A reliable deployment pattern is:

  • Schedule this script daily on Windows devices
  • Start with the default threshold/deadline (7 days / 24 hours)
  • Create a monitor or dashboard using uptimeRebootPolicyState
  • Tune threshold by device role (for example, stricter on user endpoints)

For staged rollout, run with dryRun=true first so you can validate logs and field updates without actually creating or removing tasks.

Custom field outputs after script execution

Cleanup Mode

If you need to roll back or clear existing deadline tasks, set:

  • runMode = CleanupOnly

That mode removes the reboot deadline task and exits cleanly.

Notes

note

The script can attempt to install the RunAsUser module when needed for user-context prompts/toasts. In tightly locked-down environments, test this behavior with dryRun=true first and pre-stage dependencies if required.

tip

If your support links are configured, the interactive prompt can expose quick contact options (portal/email/phone) directly from the reboot scheduling UI.