Category filter

Script to update active hours on Windows 10/11 devices

Since Windows 10, Windows has incorporated a feature named “Active hours” which lets the user indicate to the computer the time they’re most likely to use the system. It means the user will be actively using the device during the scheduled hours and not be disturbed by updates and reboots. Setting the active hours would mean that the device could no longer install updates or schedule automatic restarts at the hours configured by the user. Only after the set hours can the device perform its regular maintenance or install the updates. IT admins can run PowerShell scripts to set/update the active hours on their Windows 10/11 devices. To remotely deploy these scripts to multiple Windows devices, admins can make use of the Execute Custom Script action of Hexnode.

Disclaimer:


The sample scripts provided below are adapted from third-party open-source sites.

Batch script

Replace $1 and $2 with the start time and end time of the active hours, which can range from integer values 0-24 (0-12 meaning 12:00 A.M. to 12:00 P.M. and 13-24 meaning 1:00 P.M. to 12:00 A.M.). The script then sets the active hours in the registry to the specified values.

To give an example, if you wish to set the active hours of a device between 5:00 A.M. and 4:00 P.M., use the script:

@echo off

set "startHour=5"

set "endHour=16"

set "activeHours=%startHour%,%endHour%"

reg add "HKLM\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings" /v "ActiveHoursStart" /t REG_DWORD /d %startHour% /f

reg add "HKLM\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings" /v "ActiveHoursEnd" /t REG_DWORD /d %endHour% /f

PowerShell script

The script uses Set-ItemProperty cmdlet to configure the start and end of active hours. Replace $1 and $2 with the start time and end time of the active hours, which can range from integer values 0-24. The system can no longer initiate a forced reboot during these hours.

E.g., To set active hours between 2:00 A.M. and 8:00 P.M.,

$startHour = 2

$endHour = 20

$activeHours = "$startHour-$endHour"

Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings" -Name "ActiveHoursStart" -Value $startHour

Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings" -Name "ActiveHoursEnd" -Value $endHour

Write-Host "Active Hours set from $startHour to $endHour."

Notes:

  • The Active hours functionality only allows you to choose an end time that is no more than 18 hours from the start time.
  • You cannot create separate active hours for weekends or set multiple periods of active hours for a day.
  • It is recommended to manually validate the script execution on a system before executing the action in bulk.
  • Hexnode will not be responsible for any damage/loss to the system on the behavior of the script.

  • Sample Script Repository