Share via


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

Comments

  • Anonymous
    January 01, 2003
    is there a way to get a verbose output so that we can see all the updates installed.

  • Anonymous
    January 01, 2003
    Nice script! thanks

  • Anonymous
    January 01, 2003
    Hello,

    It must have been my lucky day as far as DISM goes. My guess is I either used ti wrong index #, or installed some particular update that had to be installed in order to show all updates, really don't have an idea.

    After I used the updated wim file 151 updates were shown compared to the original wim file that showed 109. I downloaded a fair amount of the updates, & after the installation w/ the new wim, 82 updates were shown to be left to do, which tells me the updated wim is doing as should.

    I know there's an expand command to use to export or whatever the better word may be. I'm trying to convert the IE 11.exe to a MSU file, but doesn't seem the expand command will do that.

    Thanks a lot because I can now progress further as far as integrating .msu w/ DISM

  • Anonymous
    January 01, 2003
    Nice catch Vladimir! Fixed. Matt

  • Anonymous
    January 01, 2003
    Change Mount-Wim to /Mount-Wim

  • Anonymous
    November 23, 2012
    Exactly how are you keeping track of wich patches to add to a certain wim-file? Right now, I tried to add 105 patches, "only 87" of them where applied, while some failed. Keeping track of which failed on how to correct it, seems like an impossible task. Any tips? :)

  • Anonymous
    November 25, 2013
    I see this is done through Powershell, Is this simply a batch file ran through Powershell?

  • Anonymous
    November 25, 2013
    @Eric Yep, just wrapping the dism commands in PowerShell. You could use any language to perform the loop.

  • Anonymous
    February 10, 2014
    Just wanted to thank you for this!

  • Anonymous
    February 27, 2014
    My reading of this article led me to believe that I should supply my downloaded patches as-is, in their *.msu file form. This turned out not to be the case. My attempts to apply the patches in this form repeatedly failed. Upon further research, it seems that the *.msu files need to be extracted and the *.cab files resulting from the extraction are what should be supplied to this script. If this is true as it seems to be, then this important detail should probably be supplied in this article. It could save hours of frustration from trying to apply *.msus.

    Also, under "Automating the installation", there is still a mount-wim that should be /mount-wim. While it does make people stop and read what the script is actually doing, it might be worth correcting this.

    Thanks for the write-up!

  • Anonymous
    June 17, 2014
    Ive just used this script to add 40+ MSU files to a wim file and it worked great, saved me so much time. Should this work the same for .CAB files as I get the following error

    An error occurred trying to open - I:IT Shared AreaSoftwareWindows UpdatesOffice 2010all-acsrvwfe-x-none_a5c4ba0d958241ff2cce9fbad35e4ccef8641
    81d.cab Error: 0x80070002

    Error: 2

    The system cannot find the file specified.

  • Anonymous
    February 10, 2015
    The comment has been removed

  • Anonymous
    April 01, 2015
    Thanks for the awesome script works really well

  • Anonymous
    August 09, 2015
    I don't understand why you are looping through each update. You are running the same command 1 time per update when you can run it just 1 time supplying the folder in which the updates reside. Not to mention the 10 second sleep within the loop will lengthen the process even more. Just remove the loop and change $UpdatesPath to "C:Updates" with no Asterisk behind it. No need to call Dism X number of times. Just call it once.

    $UpdatesPath = 'C:Updates'
    ......
    Dism /Image:$MountPath /Add-Package /PackagePath:$Updates

    No Loopy. It worky. However, this is a great example of how to loop in PowerShell. It's just not needed here.

    -LvilleSystemsJockey

  • Anonymous
    October 12, 2015
    I've been notified that I have pending some Windows updates. I'm not sure how to add them?

  • Anonymous
    October 20, 2015
    @LvilleSystemsJockey, thanks, I wondered why the output said "Processing 1 of 1" and if I could make it process all of the updates instead

  • Anonymous
    October 22, 2015
    Office update having exe format not getting injected using the Power shell Script. Any Idea how to correct it?

  • Anonymous
    October 22, 2015
    Hi,

    Not able to Inject Office 2010 updates which is in EXE format in to WIM using this PS script? any Idea?

    Thanks,
    Dhileep

  • Anonymous
    October 22, 2015
    Hi Dhileep. Only CBS updates can be installed in this fashion, and Office updates are not CBS compatible. To read more -https://technet.microsoft.com/en-us/library/cc756291(v=ws.10).aspx

  • Anonymous
    December 14, 2015
    Where can I download all the Windows Updates to apply to the image? I have a Windows 7 image and would like to apply all the updates up to now.

    • Anonymous
      January 12, 2016
      WSUS offline updater, them check the folder %WSUS%/client\w61\glb for windows 7
  • Anonymous
    October 28, 2016
    Is there any book on How do i add the post installation to iso?I saw the microsoft post installation talking about creating the script on $oem$/$$. But when i create the script and create the folder $$/setup/script under my distribution share $oem$ folder. It doesnt replicate the folder and script i have input.

  • Anonymous
    December 27, 2016
    Remember to apply the latest servicing stack update first, for instance, https://support.microsoft.com/en-us/kb/3020369

  • Anonymous
    March 06, 2017
    Dear Microsoft.If I slipstream a hotfix.msu into the install.wim. Will this hotfix take effect immediately during installation of a fresh Windows setup?I need the following hotfix kb982018 for my 4k native drive to correctly install Windows.

    • Anonymous
      March 13, 2017
      I'm not sure Obadiah. If you test please report back as it may help someone else! Matt
  • Anonymous
    March 07, 2017
    Think it is Get-ChildItem instead of Get-Item

    • Anonymous
      March 13, 2017
      Hey Eric - your suggestion may well be right, I wrote this script back in 2012 & it worked back then!
  • Anonymous
    December 18, 2017
    Somehow this process goes all well but in the end the OS installed using the updated ISO file picks up the same updates for download when an update check is done.

  • Anonymous
    May 23, 2018
    Make sure to adjust the index for the windows image you intend to deploy from the WIM you mounted. Run this command to see what index are your WIM . dism /get-wiminfo /wimfile:c:\TempMount\install.wimWhen using Index of 1, I was never seeing the slipstreamed patches after a TS upgrade because I was deploying a TS upgrade to Enterprise which was actually Index 3, and Index 1 was Education.

  • Anonymous
    July 11, 2018
    The comment has been removed