Introduction
Sometimes you need to install a list of hotfixes for the Windows Server or client operating system, provided as *.MSU files by Microsoft.
The issue is that KB articles that are already installed will cause the process to fail.
In this blog post, I provide a Powershell script to install a list of MSU files that you may have manually downloaded.
What are MSU files?
A *.msu file or a Microsoft Update file is 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.
The MSU files, similar to MSI files, are archived files, which contain a CAB file.
How do I extract a CAB file from an MSU?
You can extract the CAB file from an MSU file using this command line:
expand -f "<name of MSU file>" "<destination>"
An example would be:
expand -f "Windows6.1-KB2896256-x64.cab" "C:\temp\MSU"
How do I install a CAB file?
If you want to install a CAB file which you have extracted, you can use this dism command to install:
dism.exe /online /add-package /packagepath:"<cab file" /quiet /norestart /logpath:"<path to log>"
What is wusa.exe?
Wusa.exe can be found in the %WinDir%\System32 folder and contains the following data:
Content | Description |
Windows Update metadata | Describes each update package that the .msu file contains. |
One or more .cab files | Each .cab file represents one update. |
An .xml file | This .xml file describes the .msu update package. Wusa.exe uses the .xml file when you perform an unattended installation of the update 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 file | This file contains string properties that Wusa.exe uses. For example, this file includes the title of the associated article in the Microsoft Knowledge Base. |
Install MSU files using a Powershell script
The Powershell script below takes the KB articles on the list and only install those KB numbers 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
- UNC path browsing using PSDrives in Powershell
- How to read text files in a folder using Powershell
- How to use Powershell to bulk add users to Active Directory groups
- How to check if Powershell is running as administrator
really good tip!
How can I do it remotely
Can you please suggest how to unistall using powershell
Oldie, but goodie. 🙂 thanks for this, but shoulndn’t your “$SourceFolder” have a “backslash” at the end; else the “path” would be messed up?
You have this:
#Source folder
$SourceFolder = “c:\temp”
Should be:
$SourceFolder = “c:\temp\”
Notice “\” ater “temp” above, else: “$SourceFolder” would not have “\” before the “$KB”
-ArgumentList “$SourceFolder$KB.msu
I think yours would yield:
C:\tempKBname
But it should be:
C:\temp\KBname
Or leave it the way you have it, but put “\” between the 2, like this:
“$SourceFolder\$KB.msu”
Thanks Joe, you are correct! I have modified the script 🙂
thanks for the great blog would help a lot
I’m a beginner here , Daniel I would really appreciate if you could share an example like what all changes we need to make in above scripts other than KB article names
Hey very new to trying to Powershell.
I tried to use this script with the understanding that this would grab the kb and install it on the machine. I think I am missing a piece.
How could I leverage this to download and install the kb’s from the array?
Hey Justin were you able to push the KB’s if so please suggest me the solution as well I would really appreciate the same
What is your suggestion to address required restarts in this script?
Is it normal for CAB installs to take over 8Gbs of space?