PowerShell: Stopping Windows Update From Restarting Your Machine When It Suits It
Windows Update has a habit of treating your working hours like a suggestion. You step away for a coffee, come back to a machine that decided to install itself, and spend the next stretch re-opening every window, re-attaching to every session, and explaining to nothing why your unsaved work is gone. The feature exists for a reason — a patched fleet is a safer fleet — but "patched" and "mid-build" can coexist, and the machine should not get to pick the moment on its own.
You can set Active Hours in Settings, and on a normal desktop that is often enough. But it only tells Windows not to restart during those hours; an always-on box with unsaved state does not have off-hours. The real switch is a registry policy key that should live in the Windows Update UI as a plain toggle. It does not, so this post covers where it actually is, what each value does, and how to make the setting stick when Windows Update resets it.
Where the Setting Actually Lives
The switch that controls Automatic Updates behaviour is AUOptions, a DWORD under this policy key:
HKLM:\Software\Policies\Microsoft\Windows\WindowsUpdate\AU
Two things trip people up here. First, you need an elevated shell — this is an HKLM policy path, and a normal user token cannot write it. Second, on a clean machine the key often does not exist at all; it is created by Group Policy or by someone who already went down this road. So before you set anything, read what is there:
Get-ItemProperty -Path 'HKLM:\Software\Policies\Microsoft\Windows\WindowsUpdate\AU'
If that comes back empty, the key is not present and Windows Update is running on its defaults — which, as you have noticed, includes restarting whenever it likes. The documented values for AUOptions are:
- 2 — Notify before download. Nothing happens automatically; you drive everything.
- 3 — Automatically download, notify of installation. Updates land quietly, but the install waits for you to pick a time. This is the one that kills surprise restarts.
- 4 — Automatically download and schedule installation. Only meaningful if
ScheduledInstallDayandScheduledInstallTimeare also set in the same key. - 5 — Automatic Updates is required, but users can configure it themselves.
For a machine I want patched without being rebooted mid-session, 3 is the value: the patching still happens automatically, and the restart becomes my decision instead of the update's. Microsoft documents the full set of Windows Update registry values here, and it is worth a read if you are going to touch this key more than once.

The One-Liner That Gets You There
With an elevated PowerShell open, the whole change is one command:
Set-ItemProperty -Path 'HKLM:\Software\Policies\Microsoft\Windows\WindowsUpdate\AU' -Name AUOptions -Value 3
If the key does not exist yet, create it first — New-Item -Path 'HKLM:\Software\Policies\Microsoft\Windows\WindowsUpdate\AU' — then set the value. Run gpupdate /force if you want the policy applied immediately rather than on the next refresh cycle.
That is the entire fix, and for a single machine it is enough. I would keep a copy of that command in your notes anyway, because of what happens next.
Why It Keeps Getting Reset
Here is the part the one-liner does not cover. Windows Update is not a passive consumer of this key; major updates have a habit of rewriting local policy values back to whatever they think the system should be. I have been down this road on my own machines — set the value, enjoy the quiet for a while, then wake up to it having moved again after a big update landed. The setting is not broken and you did nothing wrong; the OS simply re-asserts its defaults on a schedule of its own choosing.
So the durable version of this fix is not a one-time write. It is a small script that re-asserts the value, run by a scheduled task at startup. The task costs nothing to run — it is three lines — and it means the machine comes back with its own policy in place even after an update tried to take it away.

Making It Stick: The Re-assert Script
The script itself is deliberately small, because a small script is one you can actually read and trust. Save this as, say, wu-auoptions.ps1:
$Key = 'HKLM:\Software\Policies\Microsoft\Windows\WindowsUpdate\AU'
if (-not (Test-Path $Key)) { New-Item -Path $Key | Out-Null }
Set-ItemProperty -Path $Key -Name AUOptions -Value 3
That is it. It creates the key if an update wiped it, then writes the value back. No folders to manage and no logs to parse; if you want a log, add one line that appends a timestamp to a file in the same folder, but I would keep the core this small.
Registering the task is where I would be careful about how you supply credentials. The old-school version of this setup prompts for an admin password with Read-Host, which echoes the password straight back at you on the console. Do not do that. Run PowerShell as administrator and let Get-Credential handle the input masked:
$Action = New-ScheduledTaskAction -Execute 'PowerShell.exe' `
-Argument '-NoProfile -ExecutionPolicy Bypass -File "C:\Scripts\wu-auoptions.ps1"'
$Trigger = New-ScheduledTaskTrigger -AtStartup -RandomDelay (New-TimeSpan -Minutes 5)
$Principal = New-ScheduledTaskPrincipal -GroupId 'Administrators' -RunLevel Highest
$Admin = Get-Credential -Message 'Administrative account for the task'
Register-ScheduledTask -TaskName 'WU-AUOptions-Enforce' `
-Action $Action -Trigger $Trigger -Principal $Principal `
-User $Admin.UserName -Password $Admin.GetNetworkCredential().Password
A few notes on that block. The random delay is deliberate: it keeps the task from firing at the exact same second as every other startup job, and it gives Windows time to settle before a registry write lands. The Administrators group with RunLevel Highest is what lets the task write the HKLM policy path without a logged-on user. And if New-ScheduledTaskTrigger throws an error about the task scheduler provider — a known quirk on some machines after certain updates — re-register the provider with mofcomp C:\Windows\System32\wbem\SchedProv.mof and run the same command again; it works the second time.

If You Are on a Domain
If these machines are domain-joined, stop here and do this as a Group Policy object instead. A registry write per machine is a workaround for a standalone box; a GPO that pushes AUOptions from the domain is the actual control, it applies to every machine in scope, and it survives whatever resets the local copy. The scheduled-task approach above is for the home lab and the standalone workstation — the machines where you are your own IT department.
The Short Version
Windows Update's restart behaviour is controlled by AUOptions under HKLM:\Software\Policies\Microsoft\Windows\WindowsUpdate\AU, a key that has no UI toggle and that Windows itself will happily reset. Set it to 3 from an elevated PowerShell to keep automatic patching without automatic restarts, and if you have watched it revert after a major update, pair it with a three-line re-assert script on a startup scheduled task — registered with masked credentials, not Read-Host. The machine stays patched, and it stops getting to pick the moment.
If this was useful, More hands-on tech guides at TechGeek. No pressure — read it whenever it's useful.