0% found this document useful (0 votes)
37 views

Getting Started With PowerShell and The PSWindowsUpdate Module

Uploaded by

roylopez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views

Getting Started With PowerShell and The PSWindowsUpdate Module

Uploaded by

roylopez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

4/11/24, 8:35 AM Getting Started with PowerShell and the PSWindowsUpdate Module

Don't be left behind with the ATA Learning Newsletter!



Your email address Subscribe Today!
Getting Started with PowerShell and the
PSWindowsUpdate Module
Published: 21 September 2021 - 5 min. read

POWERSHELL

Ekekenta Clara
Read more tutorials by Ekekenta Clara!

Table of Contents
Prerequisites
Installing the PSWindowsUpdate Module

Checking for Available Windows Updates


Excluding Windows Updates from Installing
Installing Windows Updates
Downloading and Installing All Available Updates
Checking Windows Update History
Uninstalling Windows Updates
Conclusion

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.

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.

https://adamtheautomator.com/pswindowsupdate/ 2/12
4/11/24, 8:35 AM Getting Started with PowerShell and the PSWindowsUpdate Module

1. Open PowerShell as administrator.


Don't be left behindLooks
with like
theyou're
ATA Learning
offline! Newsletter!

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

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.

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

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)

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.

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

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-

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

Related: How to Check for a Pending Reboot in the Registry (Windows)

Downloading and Installing All Available Updates

https://adamtheautomator.com/pswindowsupdate/ 6/12
4/11/24, 8:35 AM Getting Started with PowerShell and the PSWindowsUpdate Module

If you’re not picky when it comes to updates, running the Install-WindowsUpdate


Don't be left behindLooks
with like
theyou're
ATA Learning
offline! Newsletter!
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

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.

https://adamtheautomator.com/pswindowsupdate/ 7/12
4/11/24, 8:35 AM Getting Started with PowerShell and the PSWindowsUpdate Module

Don't be left behindLooks


Get-WUHistory with like
theyou're
ATA Learning
offline! Newsletter!

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

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

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 ▲

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?

Related: How to Build a Basic PowerShell Windows Updates Report

Hate ads? Want to support the


writer? Get many of our tutorials
packaged as an ATA Guidebook.

Explore ATA Guidebooks

More from ATA Learning & Partners

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!

Recommended Resources for


Training, Information Security,
Automation, and more!

Get Paid to Write!

ATA Learning is always seeking


instructors of all experience
levels. Regardless if you’re a
junior admin or system architect,
you have something to share.
Why not write on a platform with
an existing audience and share
your knowledge with the world?

ATA Learning Guidebooks

https://adamtheautomator.com/pswindowsupdate/ 10/12
4/11/24, 8:35 AM Getting Started with PowerShell and the PSWindowsUpdate Module

Don't be left behind with like


ATALooks theyou're
Learning ATA Learning
offline!
is known Newsletter!
for its

high-quality written tutorials in
the form of blog posts. Support
ATA Learning with ATA Guidebook
PDF eBooks available offline and
with no ads!

Continue learning with these related tutorials!

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

Get Paid to Write


Don't be left behindLooks
with like
theyou're
ATA Learning
offline! Newsletter!
Advertising ▲

Recommended Resources

Copyright 2024© ATA Learning | Privacy Policy

https://adamtheautomator.com/pswindowsupdate/ 12/12

You might also like