logo powershell

Windows updates configureren via powershell

Het instellen van updates op een server die niet in een domein hangt, kun je via powershell plannen. Je hebt dan meer mogelijkheiden dan via het “Instellingen” scherm.

In feite zetten deze powershell updrachten enkele waarden weg in de registry, die je ook middels regedit kunt instellen.



Als eerste activeren we autoupdate.

Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU -Name NoAutoUpdate -Value 0

De AUOptions waarde bepaalt wat je wil doen, enkel notificatie, of enkel downloaden met notificatie of automatisch:
2 enkel notificatie
3 automatisch downloaden met notificatie
4 automatische download op een dag en tijd.



In het voorbeeld laten de we de updates automatisch downloaden en installeren.

Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU -Name AUOptions -Value 4

Vervolgens stel je de dag van de week in. Daarbij is de nummering als volgt:

1 zondag
2 maandag
3 dinsdag
4 woensdag
5 donderdag
6 vrijdag
7 zaterdag

In het voorbeeld laten de we de updates op vrijdag plaatsvinden.

Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU -Name ScheduledInstallDay -Value 6

Als laatste stel je nog de tijd in hierbij geef je de uren op basis van een 24-uurs klok. In het voorbeeld laten de we de updates om 2:00u ’s nachts plaatsvinden.

Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU -Name ScheduledInstallTime -Value 2

Mocht je de updates slechts 1x per maand willen installeren, laten we zeggen de 1ste week van de maand, stel dan nog een van de volgende parameters in, ScheduledInstallFirstWeek, ScheduledInstallSecondWeek, ScheduledInstallThirdWeek of ScheduledInstallFourthWeek:

Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU -Name ScheduledInstallFirstWeek -Value 1

Voor de 2de week van de maand:

Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU -Name ScheduledInstallSecondWeek -Value 1

Je kunt een eerder gekozen week weer uitschakelen door als -Value 0 te nemen.

Voor het activeren van overige updates van Microsoft voer je dit commando uit:

Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU -Name AllowMUUpdateService -Value 1

Tevens wil je instellen dat na de installaties een herstart wordt uitgevoerd. Om dit te activeren voer je het volgende commando uit:

Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU -Name AlwaysAutoRebootAtScheduledTime -Value 1

Hierna stel je het aantal minuten in dat gewacht moet worden alvorens te herstarten. Dit kan een waarde tussen de 15 en 180 zijn.

Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU -Name AlwaysAutoRebootAtScheduledTimeMinutes -Value 30

Als er een herstart dient plaats te vinden, wil je uitsluiten dat er gewacht wordt op aangemelde gebruikers:

Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU -Name NoAutoRebootWithLoggedOnUsers -Value 0

Stel je wil automatisch windows- en overige microsoft updates laten downloaden en installeren op de eerste en derde vrijdag van de maand om 2:00u ’s nachts, waarbij ingelogde gebruikers na de installatie van de updates een restart timer te zien krijgen dat het systeem na 30minuten opnieuw gestart zal worden, dan krijg je dus de volgende set:

Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU -Name NoAutoUpdate -Value 0
Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU -Name AUOptions -Value 4
Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU -Name AllowMUUpdateService -Value 1
Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU -Name ScheduledInstallDay -Value 6
Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU -Name ScheduledInstallTime -Value 2
Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU -Name ScheduledInstallFirstWeek -Value 1
Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU -Name ScheduledInstallThirdWeek -Value 1
Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU -Name AlwaysAutoRebootAtScheduledTime -Value 1
Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU -Name AlwaysAutoRebootAtScheduledTimeMinutes -Value 30
Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU -Name NoAutoRebootWithLoggedOnUsers -Value 0
Stop-Service -Name "wuauserv"
Start-Service -Name "wuauserv"

Zoals je ziet zit er ook een herstart van de Windows Update Service bij om de nieuwe settings actief te maken.

Wil je een server elke tweede en vierde vrijdag van de maand de updates laten downloaden en installeren om 2:00u ’s nachts, dan krijg je dus de volgende set:

Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU -Name NoAutoUpdate -Value 0 
Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU -Name AUOptions -Value 4 
Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU -Name AllowMUUpdateService -Value 1 
Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU -Name ScheduledInstallDay -Value 6 
Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU -Name ScheduledInstallTime -Value 2 
Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU -Name ScheduledInstallSecondWeek -Value 1 
Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU -Name ScheduledInstallFourthWeek -Value 1 
Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU -Name AlwaysAutoRebootAtScheduledTime -Value 1 
Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU -Name AlwaysAutoRebootAtScheduledTimeMinutes -Value 30 
Set-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU -Name NoAutoRebootWithLoggedOnUsers -Value 0 
Stop-Service -Name "wuauserv" 
Start-Service -Name "wuauserv"






Met behulp van een get-itemproperty powershell opdracht kun je de instellingen achterhalen:

Get-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU