summaryrefslogtreecommitdiff
path: root/packer/files/scripts/windows/disable-updates.ps1
diff options
context:
space:
mode:
Diffstat (limited to 'packer/files/scripts/windows/disable-updates.ps1')
-rw-r--r--packer/files/scripts/windows/disable-updates.ps113
1 files changed, 13 insertions, 0 deletions
diff --git a/packer/files/scripts/windows/disable-updates.ps1 b/packer/files/scripts/windows/disable-updates.ps1
new file mode 100644
index 0000000..69d6441
--- /dev/null
+++ b/packer/files/scripts/windows/disable-updates.ps1
@@ -0,0 +1,13 @@
+# https://learn.microsoft.com/en-us/windows/win32/api/wuapi/ne-wuapi-automaticupdatesnotificationlevel
+# https://learn.microsoft.com/en-us/archive/blogs/jamesone/managing-windows-update-with-powershell
+try {
+ $updates = (New-Object -ComObject "Microsoft.Update.AutoUpdate").Settings
+ if ($updates.ReadOnly -eq $true) {
+ Write-Error "[ERR] Cannot update Windows Update settings due to GPO restrictions"
+ } else {
+ $updates.NotificationLevel = 1
+ $updates.Save()
+ $updates.Refresh()
+ Write-Output "[INFO] Automatic Windows Updates disabled"
+ }
+} catch { Write-Output "[ERR] Exception while disabling Automatic Windows Updates" }