Using the PowerShell PSWindowsUpdate module

I’ve been using the PSWindowsUpdate module for a while now; it’s very convenient when spinning up a test VM for a customer if you want to have it up-to-date before going through the Windows Autopilot process, for example. In this blog post, I will show you how the module works with a few examples of how I use it.

What is the PSWindowsUpdate module?

Well… The name describes its purpose, of course, but it’s a PowerShell module created and maintained by Michal Gajda and published on the PSGallery. The module contains cmdlets to manage the Windows Update Client, which is simple but efficient! And… it has been downloaded more than 500,000,000 times!!!

How to install

You can install and use it from the PSGallery by running the following:

Install-Module PSWindowsUpdate
Import-Module PSWindowsUpdate

Available cmdlets

After importing, the following cmdlets are available:

Examples

In the examples below, I use the PSWindowsUpdate module on a new Windows 11 Pro version 23h2 Hyper-V VM on my laptop that I deployed using the last ISO file from my VisualStudio subscription, released in December 2023. (I use it to install all updates before the Autopilot process so that the machine is up-to-date when deploying it)

Checking if updates are available

Running the Get-WindowsUpdate cmdlet will show you which updates are available to your system. You can use the -ComputerName parameter to connect to another system.

Installing all updates

Running the Install-WindowsUpdate cmdlet will install all the updates found and show you the progress during installation. You can use the -AcceptAll parameter to avoid answering confirmations.

It will prompt you to reboot the system if needed:

Retrieving the Windows Update history of a system

Running the Get-WUHistory cmdlet will show you the installed updates on the system, and you can use the -Last parameter to limit the number of updates returned in the list. For example, this will show you all the installed updates:

Or only show the last two by using -Last 2 to show the previous two updates:

Default only these properties are returned; using Format-List will show you more details:

Install or uninstall a specific Windows update

If you need to uninstall an update, use the Uninstall-WindowsUpdate cmdlet with the -KBArticleID parameter. In the example below, I (try, because it failed and you can’t always uninstall updates, especially when you’re not in Windows at that moment like me when running this in before logging in to start the Autopilot process) uninstall the KB4023057 update from the system:

And if you need to install an update, use the (You guessed it 😉 ) Install-WindowsUpdate cmdlet with the -KBArticleID parameter. In the example below, I installed the KB4052623 on the system, which was ready to be installed, which you can see because I ran the Get-WindowsUpdate command:

More information

You can find more Parameters and examples on the GitHub project page of PSWindowsupdate here. There are more advanced things you can do with it in comparison to the examples I showed above, such as scheduling an update from the command line for later that evening 🙂

Wrapping up

I showed you the PSWindowsUpdate module, some of its capabilities, and how to use the excellent command line method to install and manage updates using PowerShell!

One thought on “Using the PowerShell PSWindowsUpdate module

  1. Pingback: PowerShell is fun :)Installing Windows Updates on all your Hyper-V lab VMs using PowerShell and PSWindowsUpdate

Leave a Reply

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