Getting Started with PowerShell and the PSWindowsUpdate Module

Published:21 September 2021 - 5 min. read

Ekekenta Clara Image

Ekekenta Clara

Read more tutorials by Ekekenta Clara!

Installing Windows Updates manually can be a drag. Why not automate the entire process with PowerShell? Get started controlling Windows updates with the PSWindowsUpdate module in PowerShell!

In this tutorial, you will learn how to download and install updates on your Windows machine through PowerShell.

A FREE read only tool that scans your AD and generates multiple interactive reports for you to measure the effectiveness of your password policies against a brute-force attack. Download Specops Password Auditor now!

Prerequisites

This tutorial uses Windows 10 Build 19042 for demonstrations throughout this tutorial, but older ones, such as Windows 7 and 8.1, will work.

Installing the PSWindowsUpdate Module

The PSWindowsUpdate module is a third-party module available in PowerShell Gallery that lets you manage Windows updates from the PowerShell console. The PowerShell Gallery is the central repository where you can find and share PowerShell modules.

With the PSWindowsUpdate module, you can remotely check, install, update and remove updates on Windows servers and workstations. But first, you need to install the PSWindowsUpdate module on your machine.

1. Open PowerShell as administrator.

2. Run the Install-Module command to download and install the PSWindowUpdate module from the PowerShell gallery repository. The -Force parameter tells the command to ignore prompt messages and continue installing the module.

Install-Module -Name PSWindowsUpdate -Force

If you’re on an older version of Windows, you can download the PSWindowsUpdate module manually.

3. Next, run the Import-Module command below to import the PSWindowsUpdate module to PowerShell’s current session. Once imported, you can then use the module to manage Windows updates on your machine.

You may run into an error importing the module for the first time saying “The specified module ‘PSWindowsUpdate’ was not loaded”. In that case, you must allow executing scripts on your machine.

Run the command Set-ExecutionPolicy -ExecutionPolicy RemoteSigned to enable execute remote scripts on your computer. Now try importing the PSWindowsUpdate module again.

Import-Module PSWindowsUpdate

4. Finally, run the command below to see all commands (Get-Command) available for the PSWindowsUpdate module. Some of these commands are what you will use to manage Windows updates on your machine. Get-Command -Module PSWindowsUpdate

Get-Command -Module PSWindowsUpdate

Checking for Available Windows Updates

With the PSWindowsUpdate module installed, you can now run a command to list the updates available for your computer before installing them. Checking the list of updates is a good practice to avoid installing an update you don’t need.

Run the Get-WindowsUpdate command to list all the Windows updates

Get-WindowsUpdate

Below, you can see the list of available Windows updates along with their Knowledge-Base (KB) numbers. Take note of any KB number of a Windows update that you may want to prevent installing later, perhaps one that you deem not important.

Listing Available Windows Updates
Listing Available Windows Updates

Perhaps you also want to check where Windows gets an update from to see if the source is trustworthy. If so, the Get-WUServiceManager command will do the trick.

Run the Get-WUServiceManager to show the list of available update services.

Get-WUServiceManager

There’s no official documentation about the update the sources, but each is defined below:

  • Microsoft Update – the standard update source
  • DCat Flighting Prod – an alternative MS supdate ource for specific flighted update items (from previews, etc)
  • Windows Store (DCat Prod) – normally just Windows Store, but has Dcat Prod when for insider preview PC
  • Windows Update – an older update source for Windows Vista and older Windows OS.
Showing where Windows Gets Updates
Showing where Windows Gets Updates

Excluding Windows Updates from Installing

Now you’ve seen the Windows updates available, perhaps you prefer not to install some of them on your computer. In that case, you can choose not to install them by hiding them.

Run the Hide-WindowsUpdate command below to hide a Windows update tagged with the specified KB number (-KBArticleID KB4052623). You can specify the KB number you took note of in the “Checking for Available Windows Updates” section instead.

PowerShell will ask for your confirmation before executing the command. Confirm the command with the “A” key, then press Enter.

	Hide-WindowsUpdate -KBArticleID KB4052623
Hiding an Update Based on the Update's KB Number
Hiding an Update Based on the Update’s KB Number

If you change your mind and want to install the update in the future, you can show the update similar to how you hid the update. To show the update, run the Show-WindowsUpdate command along with the update’s KB number, like this: Show-WindowsUpdate -KBArticleID KB4052623

Installing Windows Updates

Now that you can discover and exclude some updates from installing, let’s now check out how to install them.

But before installing updates, checking if updates require a system reboot is a good practice. Why? Knowing whether the Windows updates require a reboot beforehand tells you to save all your work and complete other ongoing installations before diving to the Windows update.

Now run the Get-WURebootStatus command to determine if any of the Windows updates require a reboot. The command returns either True or False value to indicate the reboot status

 Get-WURebootStatus

Below, you can see the command returned a False value, which indicates a reboot is not required. So go nuts and install the updates you deem are necessary.

Checking if Reboot is Required After Installing Windows Updates
Checking if Reboot is Required After Installing Windows Updates

Downloading and Installing All Available Updates

If you’re not picky when it comes to updates, running the Install-WindowsUpdate command on its own lets you install all available Windows updates. But perhaps, you want to install the updates without having to accept prompts. If so, you need to add the -AcceptAll parameter as shown below.

Run the Install-WindowsUpdate command below to install all available Windows updates. The -AcceptAll parameter tells the command to suppress prompts and continue installing all updates.

If you prefer to reboot your computer once the installation is completed automatically, add the -AutoReboot parameter.

Install-WindowsUpdate -AcceptAll -AutoReboot
Installing All Windows Updates
Installing All Windows Updates

If you prefer to install selected updates only, add the -KBArticleID parameter in the Install-WindowsUpdate command, followed by the update’s KB number, like this: Install-WindowsUpdate -KBArticleID KB2267602

Checking Windows Update History

Now you have installed windows updates on your computer, but perhaps something has gone wrong during the installation. If so, you can check your update history using the Get-WUHistory command. The Get-WUHistory prints out all the installed updates to the console with their installation result.

Run the Get-WUHistory command below to check Windows update history.

Get-WUHistory

Below, you can see that most of the updates have the Succeeded result status, while some have InProgress status.

Viewing Windows Update History
Viewing Windows Update History

Uninstalling Windows Updates

There are times when you install an update you don’t deem important at the moment, or there are updates you suspect of causing an issue on your system. In those times, you can properly uninstall the updates with the Remove-WindowsUpdate command.

Run the Remove-WindowsUpdate command below to uninstall a Windows update tagged with a specific KB number (-KBArticleID KB2267602).

PowerShell will require confirmation before executing the command. Press the “A” key and hit enter to confirm the command.

Remove-WindowsUpdate -KBArticleID KB2267602
Uninstalling Windows Updates
Uninstalling Windows Updates

Enforce compliance requirements, block over 3 billion compromised passwords, and help users create stronger passwords in Active Directory with dynamic end-user feedback. Contact us today about Specops Password Policy!

Conclusion

Throughout this tutorial, you’ve learned about the PSWindowsUpdate Module. You’ve also gone through selectively installing and uninstalling Windows updates.

You’ve learned that you have full control over the Windows updates with PowerShell. Now, would you prefer installing updates in PowerShell over a GUI method? Perhaps learn more about building a Windows update report?

Hate ads? Want to support the writer? Get many of our tutorials packaged as an ATA Guidebook.

Explore ATA Guidebooks

Looks like you're offline!