github.com/iqoqo/nomad@v0.11.3-0.20200911112621-d7021c74d101/e2e/terraform/packer/windows/disable-windows-updates.ps1 (about) 1 $RunningAsAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator") 2 if (!$RunningAsAdmin) { 3 Write-Error "Must be executed in Administrator level shell." 4 exit 1 5 } 6 7 $service = Get-WmiObject Win32_Service -Filter 'Name="wuauserv"' 8 9 if (!$service) { 10 Write-Error "Failed to retrieve the wauserv service" 11 exit 1 12 } 13 14 if ($service.StartMode -ne "Disabled") { 15 $result = $service.ChangeStartMode("Disabled").ReturnValue 16 if($result) { 17 Write-Error "Failed to disable the 'wuauserv' service. The return value was $result." 18 exit 1 19 } 20 } 21 22 if ($service.State -eq "Running") { 23 $result = $service.StopService().ReturnValue 24 if ($result) { 25 Write-Error "Failed to stop the 'wuauserv' service. The return value was $result." 26 exit 1 27 } 28 } 29 30 Write-Output "Automatic Windows Updates disabled."