Getting Started With PowerShell and The PSWindowsUpdate Module
Getting Started With PowerShell and The PSWindowsUpdate Module
POWERSHELL
Ekekenta Clara
Read more tutorials by Ekekenta Clara!
Table of Contents
Prerequisites
Installing the PSWindowsUpdate Module
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!
https://adamtheautomator.com/pswindowsupdate/ 1/12
4/11/24, 8:35 AM Getting Started with PowerShell and the PSWindowsUpdate Module
In this tutorial, you will learn how to download and install updates on your Windows
Don't be left behindLooks
with like
theyou're
ATA Learning
offline! Newsletter!
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.
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.
https://adamtheautomator.com/pswindowsupdate/ 2/12
4/11/24, 8:35 AM Getting Started with PowerShell and the PSWindowsUpdate Module
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.
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
https://adamtheautomator.com/pswindowsupdate/ 3/12
4/11/24, 8:35 AM Getting Started with PowerShell and the PSWindowsUpdate Module
Checking Don't
for Available Windows
be left behindLooks
with theyou're
like Updates
ATA Learning
offline! Newsletter!
▲
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.
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.
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.
Get-WUServiceManager
There’s no official documentation about the update the sources, but each is defined
below:
DCat Flighting Prod – an alternative MS supdate ource for specific flighted update
items (from previews, etc)
https://adamtheautomator.com/pswindowsupdate/ 4/12
4/11/24, 8:35 AM Getting Started with PowerShell and the PSWindowsUpdate Module
Windows Store (DCat Prod) – normally just Windows Store, but has Dcat Prod when
Don't be left behindLooks
with like
theyou're
ATA Learning
offline! Newsletter!
for insider preview PC ▲
Windows Update – an older update source for Windows Vista and older Windows OS.
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.
https://adamtheautomator.com/pswindowsupdate/ 5/12
4/11/24, 8:35 AM Getting Started with PowerShell and the PSWindowsUpdate Module
If you changeDon't
yourbe
mind
left and want
behind tolike
with
Looks install
the ATAthe
you're updateNewsletter!
Learning
offline! 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-
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.
https://adamtheautomator.com/pswindowsupdate/ 6/12
4/11/24, 8:35 AM Getting Started with PowerShell and the PSWindowsUpdate Module
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.
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:
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.
https://adamtheautomator.com/pswindowsupdate/ 7/12
4/11/24, 8:35 AM Getting Started with PowerShell and the PSWindowsUpdate Module
Below, you can see that most of the updates have the Succeeded result status, while
some have InProgress status.
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.
PowerShell will require confirmation before executing the command. Press the “A” key
and hit enter to confirm the command.
https://adamtheautomator.com/pswindowsupdate/ 8/12
4/11/24, 8:35 AM Getting Started with PowerShell and the PSWindowsUpdate Module
Enforce compliance
Don't berequirements, block
left behindLooks
with over
theyou're
like 3offline!
billion compromised
ATA Learning Newsletter! passwords, and
help users create stronger passwords in Active Directory with dynamic end-user ▲
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?
https://adamtheautomator.com/pswindowsupdate/ 9/12
4/11/24, 8:35 AM Getting Started with PowerShell and the PSWindowsUpdate Module
Recommended
Don't be left behind with like
Looks ATAResources!
theyou'reLearning
offline! Newsletter!
▲
https://adamtheautomator.com/pswindowsupdate/ 10/12
4/11/24, 8:35 AM Getting Started with PowerShell and the PSWindowsUpdate Module
CATEGORIES
IT Ops
Cloud
DevOps
Home Ops
Information Security
Software Development
SITE
Home
Tutorials
Guidebooks
Instructors
https://adamtheautomator.com/pswindowsupdate/ 11/12
4/11/24, 8:35 AM Getting Started with PowerShell and the PSWindowsUpdate Module
Recommended Resources
https://adamtheautomator.com/pswindowsupdate/ 12/12