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.
Batch script
1 2 3 4 5 6 7 8 9 |
@echo off set "startHour= $1" set "endHour= $2" 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 |
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
1 2 3 4 5 6 7 8 9 |
$startHour = $1 $endHour = $2 $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." |
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."