Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rework conditionals in Set-WindowsUpdateServer #1933

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 46 additions & 14 deletions daisy_workflows/image_build/windows/post_install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -73,28 +73,60 @@ function Set-WindowsUpdateServer {
Set the Windows update server to a WSUS server.
#>

# Test connectivity to new server before setting registry values
$wu_server_address = $script:wu_server_url.Remove(0,$script:wu_server_url.LastIndexOf('/')+1)
Write-Host "Set-WindowsUpdateServer: Testing connection to $wu_server_address."
if (-not (Test-Connection $wu_server_address -Count 1 -ErrorAction SilentlyContinue)) {
if (-not (Test-Connection download.microsoft.com -Count 1 -ErrorAction SilentlyContinue)) {
throw 'Set-WindowsUpdateServer: Windows update server is not reachable. Cannot complete image build.'
}
Write-Host "Set-WindowsUpdateServer: $wu_server_address not reachable, defaulting to Microsoft servers"
return
}

# Set the registry keys to use a WSUS 6.x server if different from current settings.

$changed = $False
if (-not (Test-Path $windows_update_path)) {
New-Item -Path $windows_update_path -Value ""
$changed = $True
}
$windows_update_item = Get-Item $windows_update_path

if (-not (Test-Path $windows_update_au_path)) {
New-Item -Path $windows_update_au_path -Value ""
$changed = $True
}
$windows_update_au_item = Get-Item $windows_update_au_path

Write-Host "Set-WindowsUpdateServer: Attempting to set Windows update server to $script:wu_server_url`:$script:wu_server_port"
$server = "$script:wu_server_url`:$script:wu_server_port"

$wu_server_address = $script:wu_server_url.Remove(0,$script:wu_server_url.LastIndexOf('/')+1)
Write-Host "Set-WindowsUpdateServer: Testing connection to $wu_server_address."
if (-not (Test-Connection $wu_server_address -Count 1 -ErrorAction SilentlyContinue)) {
if (-not (Test-Connection download.microsoft.com -Count 1 -ErrorAction SilentlyContinue)) {
throw 'Set-WindowsUpdateServer: Windows update server is not reachable. Cannot complete image build.'
}
Write-Host "Set-WindowsUpdateServer: $wu_server_address not reachable, defaulting to Microsoft servers"
return
}
if ($server -Ne $windows_update_item.GetValue("WUServer", $Null)) {
Write-Host "Set-WindowsUpdateServer: changing WUServer to [$server]."
New-ItemProperty -Path $windows_update_path -Name WUServer -Value $server -PropertyType String
$changed = $True
}

if ($server -Ne $windows_update_item.GetValue("WUStatusServer", $Null)) {
Write-Host "Set-WindowsUpdateServer: changing WUStatusServer to [$server]."
New-ItemProperty -Path $windows_update_path -Name WUStatusServer -Value $server -PropertyType String
$changed = $True
}

# Set the registry keys to use a WSUS 6.x server.
New-ItemProperty -Path $windows_update_path -Name WUServer -Value "$script:wu_server_url`:$script:wu_server_port" -PropertyType String
New-ItemProperty -Path $windows_update_path -Name WUStatusServer -Value "$script:wu_server_url`:$script:wu_server_port" -PropertyType String
if (1 -Ne $windows_update_au_item.GetValue("UseWUServer", $Null)) {
Write-Host "Set-WindowsUpdateServer: setting UseWUServer to [1]."
New-ItemProperty -Path $windows_update_au_path -Name UseWUServer -Value 1 -PropertyType DWord
$changed = $True
}

if (1 -Ne $windows_update_au_item.GetValue("NoAutoUpdate", $Null)) {
Write-Host "Set-WindowsUpdateServer: setting NoAutoUpdate to [1]."
New-ItemProperty -Path $windows_update_au_path -Name NoAutoUpdate -Value 1 -PropertyType DWord
Write-Host "Set-WindowsUpdateServer: Set Windows update server to $script:wu_server_url`:$script:wu_server_port, rebooting."
$changed = $True
}

if ($changed) {
Write-Host "Set-WindowsUpdateServer: Settings changed, rebooting."
shutdown /r /t 00
exit
}
Expand Down