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 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:
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 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 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 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”