Applying Windows Updates to a base WIM using DISM and Powershell

Manual installation

Firstly, locate your most up to date image and make a copy of it. This is so we can
stream the newest Windows Updates into the mounted WIM without risk of damaging
a working WIM. I suggest copying the WIM to a temp location. Also, put the
Windows Update that you want to apply into an Updates folder.

Next, mount your image in the temp location.

 DISM /Mount-Wim /WimFile:C:\TempMount\install.wim /index:1 /Mountdir:C:\TempMount\Mount

Now inject the Windows Update you need to apply

 DISM /image:C:\TempMount\Mount /Add-Package /Packagepath:C:\Updates\

Finally, save an unmount the image

 DISM /Unmount-Wim /Mountdir:C:\TempMount\Mount /commit
DISM /Cleanup-Wim

Automating the installation

While running updates manually like this is an easy way to apply a few updates, hundreds of updates require more work. Here’s how you would apply the updates using PowerShell.

 $UpdatesPath = "C:\Updates\*"
$MountPath = “C:\TempMount\Mount”
$WimFile = “C:\TempMount\install.wim”
DISM \Mount-Wim /WimFile:$WimFile /index:1 /Mountdir:$MountPath
$UpdateArray = Get-Item $UpdatesPath
ForEach ($Updates in $UpdateArray)
{
DISM /image:$MountPath /Add-Package /Packagepath:$Updates
Start-Sleep –s 10
}
Write-Host "Updates Applied to WIM"
DISM /Unmount-Wim /Mountdir:$MountPath /commit
DISM /Cleanup-Wim

Using SCCM 2007 Deployment Packages makes getting these updates really simple. Package up the updates like you would normally, then set the $UpdatesPath variable above to the SMS package location.

Happy patching!

Matt Shadbolt