Need Help with Windows 11 Updates in Automated Builds

0
6
Asked By TechieTalk23 On

I'm currently working on an automated build of a Windows 11 24H2 image using Packer. I found that the Windows update plugin doesn't function when building an image in Audit mode, so I'm looking for alternative methods to install Windows updates. I've learned that I can't just run a PowerShell script with PSWindowsUpdates directly; I need to use Invoke-WUJob instead. I've managed to automate the installation of the module, but when I try to execute my Invoke-WUJob script, it creates a scheduled task that just stays in a 'Queued' state. I'm not sure where I went wrong and would appreciate any insights. Here's the code I'm using: Invoke-WUJob -ComputerName localhost -RunNow -Confirm:$false -Script { Install-WindowsUpdate -MicrosoftUpdate -AcceptAll -ForceDownload -ForceInstall -IgnoreReboot -Category 'Security' } Get-ScheduledTask -TaskName 'PSWindowsUpdate' do { $scheduledTask = Get-ScheduledTask -TaskName 'PSWindowsUpdate' Write-Host 'PSWindowsUpdate task: $($scheduledTask.State)' Start-Sleep -Seconds 10 } while ($scheduledTask.State -ne 'Ready') $taskExists = Get-ScheduledTask -TaskName 'PSWindowsUpdate' if ($taskExists) { Get-ScheduledTask -TaskName 'PSWindowsUpdate' Unregister-ScheduledTask -TaskName 'PSWindowsUpdate' -Confirm:$false } else { Write-Host 'PSWindowsUpdate isn't listed as a Scheduled Task.' }

5 Answers

Answered By ScriptNinja99 On

This doesn't directly fix your issue, but try not to use back ticks for line continuation; they can lead to confusion in scripts. The blog I read suggests alternative ways to format your code. You might want to consider that.

Answered By ScriptMaster2000 On

If you're troubleshooting scripts that aren't interactive, I recommend using the Start-Transcript command to log the output to a file. This way, you can see what happens during the execution. You can use Get-Content with -Wait to continuously check the file for updates instead of repetitively opening it in Notepad. Good luck with your build!

Answered By CodeWizard42 On

Have you tried running your code outside of Audit mode? It sometimes helps to isolate the issue. Also, consider adding some logging to confirm whether the problem is with the loop or if Windows Update isn't running at all.

Answered By DevLog89 On

I'm with you on the back ticks. I know they're meant for readability, but honestly, they can complicate things. Splatting might be a more functional approach that allows you to format and manipulate your scripts more easily.

Answered By PowerShellPro On

Instead of using PSWindowsUpdate, you could leverage DISM to install updates. You can call dism.exe directly or use a PowerShell module that wraps around it. It might simplify your process.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.