Install MSU files using Powershell

Introduction

Sometimes you need to install a list of hotfixes, provided as *.MSU files by Microsoft. KB articles already installed will, by default, fail.

In this blog post, I provide a Powershell script you can use to install a list of MSU files.

What are MSU files?

A *.msu file, or a Microsoft Update file is a packaged used by Microsoft Update. This file is installed using the stand-alone installer wusa.exe. The stand-alone installer is run automatically when installing an update through Microsoft Update, but it can also be triggered manually.

What is wusa.exe?

Wusa.exe can be found in the %WinDir%\System32 folder and contain the following data:

ContentDescription
Windows Update metadataDescribes each update package that the .msu file contains.

One or more .cab filesEach .cab file represents one update.

An .xml fileThis .xml file describes the .msu update package. Wusa.exe uses the .xml file when you perform an unattended installation of the update by using the Package Manager tool (Pkgmgr.exe).

For example, you download hotfix 934307. The Windows6.0-KB934307-x86.msu file is in the C:\934307 folder. You type the following command at a command prompt to expand the .msu file to a temporary folder:

expand -f:* “C:\934307\Windows6.0-KB934307-x86.msu” %TEMP%
Then, you type the following command at a command prompt:

pkgmgr.exe /n:%TEMP%\Windows6.0-KB934307-x86.xml
A properties fileThis file contains string properties that Wusa.exe uses. For example, this file contains the title of the associated article in the Microsoft Knowledge Base.

Source: https://support.microsoft.com/en-us/help/934307/description-of-the-windows-update-standalone-installer-in-windows

Install MSU files using a Powershell script

The Powershell script below takes the KB articles on the list and only install those not already installed.

Just change the Powershell script according to your requirements.

#Source folder
$SourceFolder = "c:\temp"

#Crete new Powershell object
$KBArrayList = New-Object -TypeName System.Collections.ArrayList 

#Mofify KB article list
$KBArrayList.AddRange(@("KB2775511""KB2533623","KB2639308","KB2670838","KB2729094","KB2731771","KB2786081","KB2834140","KB2882822","KB2888049","")) 

foreach ($KB in $KBArrayList) { 
    if (-not(Get-Hotfix -Id $KB)) { 
        Start-Process -FilePath "wusa.exe" -ArgumentList "$SourceFolder$KB.msu /quiet /norestart" -Wait } 
} 

Related Posts

Subscribe to newsletter:

If you want to receive the latest news for MEMCM, Windows 10, and Powershell, please subscribe to my monthly newsletter!

3 COMMENTS

LEAVE A REPLY

Please enter your comment!
Please enter your name here