Run Windows Update From PowerShell
Join me as I use a PowerShell modules to trigger checking for Windows Updates and install them.
I've been recently playing with a lot of labs and I found an old lab I had which hadn't been patched since July 2019! I wanted to get it back up and running again, and I thought can I do it from PowerShell and the answer is yes!
There is a module that has been created by Michal Gajda that can trigger checking for updates and then install those updates. I love these kinda wee things that can help make life a little easier.
Install Module
The first thing that you need to do is install the module, this will require NuGet installed so if you haven't already got that make sure you do that.
To install the module use the command:
Install-Module PSWindowsUpdate
Get Updates
How that the module is installed you'll want to check for updates on your server, that command is:
Get-WindowsUpdate
Install Updates
Once you've triggered the server to check for updates you'll want to install them, that command is:
Install-WindowsUpdate
You can add the -AcceptAll switch to allow the system to accept them without prompting you again.
Uses
Now you can do the above on a machine to save you interfacing with the GUI or you can use it to schedule updates or even apply updates to remote machines. It's worth checking out the help and examples within the module as it has some great advice.
Script
I've pulled together a quick script that can be used to deploy the module and pre-requisites and install the needed patches, you can find a copy here or below.