mwrock/packer-templates

patching improvements?

Closed this issue · 2 comments

Hi,

Thanks very much for putting this together. I've noticed that the patching functionality downloads and installs patches one-at-a-time until done. Is it possible to download all outstanding patches prior, and then installing them as a bundle?

I think this is controlled by this line in the package.ps1 script:
Install-WindowsUpdate -AcceptEula

I'm not sure where that utility is coming from, or if it's configurable, but it'd be nice if it could be made to download all the patches before installing them. Below is a code snippet that might do the job if it could be incorporated, perhaps with a script parameters to enable/disable WSUS and point to a particular WSUS repo.

Thanks.

-Dave

New-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate -Name "WUServer" -PropertyType "String" -Value 'http://wsus0864.nordstrom.net:80'
New-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate -Name "WUStatusServer" -PropertyType "String" -Value 'http://wsus0864.nordstrom.net:80'

$Criteria = "IsInstalled=0 and Type='Software'"
$Searcher = New-Object -ComObject Microsoft.Update.Searcher
$SearchResult = $Searcher.Search($Criteria).Updates
if ($SearchResult.Count -eq 0) {
exit 0
}
$Session = New-Object -ComObject Microsoft.Update.Session
$Downloader = $Session.CreateUpdateDownloader()
$Downloader.Updates = $SearchResult
$Downloader.Download()
$Installer = New-Object -ComObject Microsoft.Update.Installer
$Installer.Updates = $SearchResult
$Result = $Installer.Install()
if ($Result.rebootRequired) {
Restart-Computer -force
}

Its coming from Boxstarter (https://github.com/mwrock/boxstarter/blob/master/Boxstarter.WinConfig/Install-WindowsUpdate.ps1) I actuallu used to have it batch downloads and updates. The problem with doing it the way I used to is that there was no output durring the mass download and you had no idea where the progress was. I have not done any benchmarking but I'm not certain the current approach is significantly slower (but I'm sure it is slower).

I do know there is another way do do it but its just trickier to write in powershell. Its one of those things where i get the time I want to rewrite it but I just have too many projects in front of that right now.

Fair enough. Thanks for the reply Matt.