$message = "Do you want to enable installing updates automatically?"
$yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes", `
  "Enables installing updates automatically."
$no = New-Object System.Management.Automation.Host.ChoiceDescription "&No", `
  "Does nothing."
$options = [System.Management.Automation.Host.ChoiceDescription[]]($yes, $no)
$result = $host.ui.PromptForChoice($title, $message, $options, 1)
switch ($result) {
  0 {
    $dir = 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU'
    if (!(Test-Path $dir)) {
      New-Item HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate
      New-Item $dir
    }
    Set-ItemProperty $dir -Name ScheduledInstallDay -Type DWORD -Value 0
    Set-ItemProperty $dir -Name ScheduledInstallTime -Type DWORD -Value 12
    Set-ItemProperty $dir -Name AUOptions -Type DWORD -Value 4
    if ([System.IntPtr]::Size -eq 8) {
      $dir = 'HKLM:\SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\WindowsUpdate\AU'
      if (!(Test-Path $dir)) {
	New-Item HKLM:\SOFTWARE\Wow6432Node\Policies\Microsoft\Windows\WindowsUpdate
	New-Item $dir
      }
      Set-ItemProperty $dir -Name ScheduledInstallDay -Type DWORD -Value 0
      Set-ItemProperty $dir -Name ScheduledInstallTime -Type DWORD -Value 12
      Set-ItemProperty $dir -Name AUOptions -Type DWORD -Value 4
    }
  }
}
