Bulk Install Windows MSU Files Automatically with PowerShell

Sign up to access this lesson

Click here to sign up and get access to this lesson!

Saving Progress...

The Manual Method

One way to handle this is the manually launch each window update installer file. This will result in you seeing a screen like the screenshot below for anywhere from 10-30 minutes for EACH update.

Manual

Obviously, this is an inefficient method and a huge time waster. I was contacted by someone who had to install roughly 50 updates and the process would have taken them several days to complete.

What's most frustrating is if your computer doesn't need the update then after waiting 20 minutes or so you will see a message like this:

Updates Are Not Applicable

Not very ideal... The PowerShell script below is automated and will make the installation process MUCH faster.

Before running the script

Before you can get started this script assumes that you have downloaded all of your update files under a single folder. It's ok to have subfolders, but keep them all in one place.

Your update folder should look something like this:

Windowsupdates

I have all of the update files under the "C:\Updates" path.

Update files have VERY long names so it's important that you place them under the C:\ drive and inside of a folder name with NO SPACES

If your updates are located inside of a folder with spaces in the name (I.E. your desktop) the script will not work. The easiest way to make things go smoothly is to place them under the C drive.

View the Windows Update logs

Before you install your updates you want to open the event viewer and navigate to Windows Logs > Setup.

Once we install the updates we will be looking for the source "WUSA" and "Servicing". This is where you will find out why certain updates were not installed, if they were successfully installed or if they require a reboot.

Consider clearing the log if you can or at least note the time when you start so you can easily find the logs later.

Eventlogs

You can filter your log for WUSA and Servicing as well by clicking Filter Current Log on the right-hand side:

Filter Event Viewer

Bulk install Windows Update FIles with PowerShell

To get started writing the script be sure that you run PowerShell as an Administrator when you launch the PowerShell ISE:

Powershell Ise

First, you can copy the full script which is outlined below. After that, I will explain what is going on so you can better understand how to write these types of scripts yourself.

Full script:


# Run this script / ISE as administrator!
# Update these variables
$UpdatePath = "C:\Updates"

# Old hotfix list
Get-HotFix > "$UpdatePath\old_hotfix_list.txt"

# Get all updates
$Updates = Get-ChildItem -Path $UpdatePath -Recurse | Where-Object {$_.Name -like "*msu*"}

# Iterate through each update
ForEach ($update in $Updates) {

# Get the full file path to the update
$UpdateFilePath = $update.FullName

# Logging
write-host "Installing update $($update.BaseName)"

# Install update - use start-process -wait so it doesnt launch the next installation until its done
Start-Process -wait wusa -ArgumentList "/update $UpdateFilePath","/quiet","/norestart"
}

# Old hotfix list
Get-HotFix > "$UpdatePath\new_hotfix_list.txt"

At the top, we are declaring a variable of $UpdatePath. That is just so you can easily change where the update files are located in your environment.

Next, we get all files in that path with a name like *msu*. This is the Windows Update KB installer file extension. This will store all of those update files in the $Updates variable. We can later call the $Update variable and its properties:

Updates

Next, we are going to start a ForEach loop. This will take all of the items in the $Updates array object and iterate over them one by one and execute commands on each item called $Update.

Sign up to access the rest of this lesson

You must either log in or sign up to access this lesson.

Saving Progress...

0 0 votes
Lesson Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments

Administration and Automation with Windows PowerShell

0%

0/1 Lessons

Course Introduction

• 5min

0 / 2 lessons complete

Getting Started with Windows PowerShell

• 42min

0 / 7 lessons complete

Getting Help and Finding Commands

• 39min

0 / 6 lessons complete

PowerShell Command Syntax

• 33min

0 / 5 lessons complete

PowerShell Objects and Properties

• 35min

0 / 6 lessons complete

The PowerShell Pipeline

• 24min

0 / 2 lessons complete

PowerShell Providers

• 30min

0 / 5 lessons complete

PowerShell Arrays and Variables

• 28min

0 / 4 lessons complete

PowerShell Loops

• 19min

0 / 3 lessons complete

PowerShell Conditional Statements

• 11min

0 / 1 lessons complete

On Premises Lab Setup

• 36min

0 / 8 lessons complete

Basic Domain Administration with Windows PowerShell

• 2hr 27min

0 / 10 lessons complete

Send Emails with PowerShell

• 22min

0 / 2 lessons complete

PowerShell Desired State Configuration (DSC) Basics

• 1hr 48min

0 / 6 lessons complete

Course Conclusion

• 1min

0 / 1 lessons complete