PowerShell | Set Windows Update Automatic Restart, Straight!

With Windows 10 being helpful and wanting to update and RESTART for you.

This is a good feature and bad. Good because everyone is updated but bad because you might suffer from a very inconvenient restart. You can put in work times for when you don’t want it to restart however if you have your computer on all the time and leave lots of windows and projects open and come back to find that your computer has restarted and spend the next 5,10,15 mins just getting everything setup just how it was.

 

To have control over this we have to go through Group Policy or the Registry. This setting should really be an option in the Windows Update settings.  This one is pretty straight forward.

We are going to do this the PowerShell way rather than going through Local Group Policy settings. If this is done through a domain then definitely do this through a GPO.

 

Of course fire up the PowerShell as an admin

Sample of what it currently looks like

Get-ItemProperty-Path ‘HKLM:\Software\Policies\Microsoft\Windows\WindowsUpdate\AU’
Perhaps how you want to set it.
Set-ItemProperty -Path ‘HKLM:\Software\Policies\Microsoft\Windows\WindowsUpdate\AU’ -Name AUOptions -Value 3
More options and details
AUOptions    Reg_DWORD   Range = 2|3|4|5
– 2 = Notify before download.
– 3 = Automatically download and notify of installation.
– 4 = Automatically download and schedule installation. Only valid if values exist for ScheduledInstallDay and ScheduledInstallTime.
– 5 = Automatic Updates is required and users can configure it.
For a complete list of all the registry values to do with Windows Update go here https://msdn.microsoft.com/en-us/library/dd939844(v=ws.10).aspx
So it seems that its not persistent so i have a revised edition below.
<#
.SYNOPSIS
Windows Update No Restart Persistent Setup
.DESCRIPTION
Since windows updates change this registry setting we will write a script to fix it.
Schedule task to check or. And set after 5 mins of log in.
Error if you are getting an error on
New-ScheduledTaskTrigger : Method please run
mofcomp C:\Windows\System32\wbem\SchedProv.mof
Get-ItemProperty -Path ‘HKLM:\Software\Policies\Microsoft\Windows\WindowsUpdate\AU’
Tested on Windows 10 Pro
.EXAMPLE
 
.NOTES
Author. Luke Keam
Company Name. techgeek.biz
Published. on 21/09/2017 AUS
Version. 1
Copyright. Free for personal and commercial use. As long as reference kept.
 
Questions, comments, suggestions always welcome. Please email me.
.LINK
Website. techgeek.biz
#>
# Folder Location
$FolderLocation = ‘C:\Program Files\techgeek.biz\Windows Update Persistent’
# Checking local folder and making it if not
$OutfileLocationtechgeek=Test-Path”C:\Program Files\techgeek.biz”
if($OutfileLocationtechgeek-ne$True) {mkdir “C:\Program Files\techgeek.biz”|Out-Null}
if($OutfileLocationtechgeek-eq$True) {Write-Host”Thank you for continue using techgeek.biz :D”}
$OutfileLocationFolderLocation=test-path”$FolderLocation”
if($OutfileLocationFolderLocation-ne$True) {mkdir “$FolderLocation”|Out-Null}
# Test item properties
$RegWindowsUpdate = ‘HKLM:\Software\Policies\Microsoft\Windows\WindowsUpdate’
if ((Test-Path -Path “$RegWindowsUpdate”) -eq $False) {New-Item -Path “$RegWindowsUpdate” | Out-Null }
 
$RegWindowsUpdateAU=’HKLM:\Software\Policies\Microsoft\Windows\WindowsUpdate\AU’
if((Test-Path-Path “$RegWindowsUpdateAU”)-eq$False)
{New-Item-Path “$RegWindowsUpdateAU”|Out-Null
New-ItemProperty-Path “$RegWindowsUpdateAU”-Name AUOptions -Value 3|Out-Null
New-ItemProperty-Path “$RegWindowsUpdateAU”-Name NoAutoUpdate -Value 0|Out-Null
New-ItemProperty-Path “$RegWindowsUpdateAU”-Name ScheduledInstallDay -Value 0|Out-Null
New-ItemProperty-Path “$RegWindowsUpdateAU”-Name ScheduledInstallTime -Value 1|Out-Null
}
# Output this to a .ps1 file
$WindowsUpdatePersistent = ‘C:\Program Files\techgeek.biz\Windows Update Persistent\Windows Update Persistent.ps1’
# Text to write out to .ps1 file
$WindowsUpdatePersistentConent=”# Set Windows Update option
Set-ItemProperty -Path ‘HKLM:\Software\Policies\Microsoft\Windows\WindowsUpdate\AU’ -Name AUOptions -Value 3
<# AUOptions    Reg_DWORD   Range = 2|3|4|5
– 2 = Notify before download.
– 3 = Automatically download and notify of installation.
– 4 = Automatically download and schedule installation. Only valid if values exist for ScheduledInstallDay and ScheduledInstallTime.
– 5 = Automatic Updates is required and users can configure it.
#>”
$WindowsUpdatePersistentConent|Out-File-FilePath $WindowsUpdatePersistent
 
# Set Scheduled Task
$NewScheduledTaskAction = New-ScheduledTaskAction -Execute “PowerShell.exe” -Argument “-NoProfile -ExecutionPolicy Bypass -File “”C:\Program Files\techgeek.biz\Windows Update Persistent\Windows Update Persistent.ps1″””
try {$NewScheduledTaskTrigger=New-ScheduledTaskTrigger-AtStartup -RandomDelay 600-ErrorAction Stop}
catch {mofcomp C:\Windows\System32\wbem\SchedProv.mof
$NewScheduledTaskTrigger=New-ScheduledTaskTrigger-AtStartup -RandomDelay 600}
$NewScheduledTaskPrincipal = New-ScheduledTaskPrincipal -GroupId “Administrators” -RunLevel Highest
$NewScheduledTask = New-ScheduledTask -Action $NewScheduledTaskAction -Trigger $NewScheduledTaskTrigger -Principal $NewScheduledTaskPrincipal
# Query for admin account
$AdminUser = Read-Host “Admin account Name? “
$AdminUserPassword=Read-Host”Admin account Password? “
 
$NewScheduledTask | Register-ScheduledTask -TaskName “Windows Update no restart persistent1” -User “$AdminUser” -Password “$AdminUserPassword” | Out-Null
gpupdate /force
Read-Host “All done!
Thank you for using techgeek.biz
Press the any key to continue”
 
Luke Keam

Luke Keam

Thank you for reading.

Any questions, comments or suggestions please leave a message below

Have a great day from

Luke Keam
techgeek.biz

 
 
Luke Keam

Latest posts by Luke Keam (see all)

Facebooktwittergoogle_plus