Injecting Windows updates with DISM (into Wim)


In this article I will be injecting Windows updates with DISM into an offline Wim image.

For work reasons, I was asked to update a Windows 7 image with the latest Windows security updates, using MDT. For me, the problem of that is that if, during injection, an update fails to be imported to the Wim, the overall MDT process fails – and no, I can’t just ignore errors. Trying to inject updates one by one, and determine which one is not applicable to the image, using MDT, is, in my opinion, a big waste of time!

So, how can one determine if a windows update is not applicable to a certain wim image? That’s where DISM comes into play.


The Solution – Injecting Windows updates with DISM

I already had a folder prepared on my D: drive with all the updates I needed to import into MDT and then into the Wim image, but, if you are not using MDT or, if you are just searching for a simple, yet effective, way of importing a bunch of Windows updates into a Wim, just create a folder on one of your drives with all the updates to import.

In my case, I placed all these updates in a folder called “UpdatesMay2019”, in the drive D: of my working computer. I had around 45 security updates to inject and to inject them one by one, would be a real pain, so below, you will find a  small powershell script which will automatically mount the wim image, inject the updates one by one and then close and save the wim with the new updates.

All updates downloaded from Microsoft Update Catalog.


The Script

#### Adjust the variable values to meet your needs ####

$UpdatesPath = "D:\UpdatesMay2019\*"
$WimMountPath = "D:\WimTemp"
$WimFile = "D:\WimMay2018.wim"
DISM /Mount-Wim /WimFile:$WimFile /index:1 /Mountdir:$WimMountPath
$UpdateArray = Get-Item $UpdatesPath
ForEach ($Update in $UpdateArray){
DISM /image:$WimMountPath /Add-Package /Packagepath:$Update
Start-Sleep -Seconds 10
Write-Host "Updates Applied to WIM"
DISM /Unmount-Wim /Mountdir:$WimMountPath /commit
DISM /Cleanup-Wim


If you would do it differently or have any suggestions, please let me know in the comments below!

If you’d like to read more Powershell articles, browse my Powershell category.


As always, if you found this article useful, share it with your friends.

If you have any questions or suggestions, leave your comment.

Thank you for reading!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Holler Box