open-nomad/e2e/terraform/packer/windows-2016-amd64/disable-windows-updates.ps1
Tim Gross 7e4a35ad7e
e2e: use more specific names for OS/distros (#9204)
We intend to expand the nightly E2E test to cover multiple distros and
platforms. Change the naming structure for "Linux client" to the more precise
"Ubuntu Bionic", and "Windows" to "Windows 2016" to make it easier to add new
targets without additional refactoring.
2020-10-28 12:58:00 -04:00

31 lines
906 B
PowerShell
Executable file

$RunningAsAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")
if (!$RunningAsAdmin) {
Write-Error "Must be executed in Administrator level shell."
exit 1
}
$service = Get-WmiObject Win32_Service -Filter 'Name="wuauserv"'
if (!$service) {
Write-Error "Failed to retrieve the wauserv service"
exit 1
}
if ($service.StartMode -ne "Disabled") {
$result = $service.ChangeStartMode("Disabled").ReturnValue
if($result) {
Write-Error "Failed to disable the 'wuauserv' service. The return value was $result."
exit 1
}
}
if ($service.State -eq "Running") {
$result = $service.StopService().ReturnValue
if ($result) {
Write-Error "Failed to stop the 'wuauserv' service. The return value was $result."
exit 1
}
}
Write-Output "Automatic Windows Updates disabled."