Estimated reading time: 5 minutes
To inject Windows Updates into custom-built images that you are using in your Configuration Manager OSD environment, you may find that keeping them up to date is a real problem. If you are happy with the image itself and do not want to make any changes to it, why should you need to rebuild and recapture it to include all the latest Windows Updates?
One solution is to install Windows Updates during your OSD task sequence which is great, but very time-consuming if your image is a few months (in some cases years!) old.
However, there is a way of injecting Windows Updates into your custom WIM files offline and then simply redistributing your WIM file to your local and remote distribution points. You used to have to install WAIK to do this, however, as Windows 10 has DISM built into it, you can now simply use your standard client Windows operating system and take advantage of a little PowerShell scripting.
Below is the guide on how to carry this out and a list of downloads that you will require.
Download
Instructions
STAGE 1 – Download required offline Windows Updates
Download the WSUS Offline Tool from the link above and extract the zip file to a directory on your computer – for this guide purposes, we will use “D:WSUS” (although most people will use a C: drive location).
Run the “UpdateGenerator.exe” file located in the root of extracted files.
You will be presented with a program and you can select the versions of Windows, Office and Legacy products that you wish to update. Remember to include (or exclude) the x86 and x64 versions if you want to update these different architectures.
You also have the option to use a WSUS server on your local network to retrieve the Windows Updates from (this is much quicker if you have a slower internet connection). To do this, click the WSUS button at the bottom and enter the URL of your WSUS server:
If you wish to download all the available updates from the Windows Update server, do not enter any information into this setting.
Once you have selected all the options that you want to download updates for, press the Start button at the bottom left. A command box will appear and will start to download all the required updates – this can take a long time depending on your selections and internet speed. These updates will be copied into the folder structure of the extracted files (“D:WSUS”).
Please note that although the first set of downloads will take a while, you can then run this process again at a later date and it will only download any newer updates required. This way you can keep an up-to-date repository of offline Windows Updates.
Once all your updates have been downloaded, you should then continue with the next stage of the process.
STAGE 2 – Inject Windows Updates into your WIM file
You should copy your WIM file to a location on your Windows 10 client machine, for this guide, we will use “D:WIM”.
You then need to create a temporary directory that will be used to mount the WIM image, we will go ahead and use “D:WIMTEMP”.
You then need to ensure that you use the correct index number by running the following command:
dism /get-wiminfo /wimfile:D:WIMwimname.wim
As you can see from the above image, the index we need to use for this process is “index:2” – however this can change depending on how you have created or captured your WIM file so you should always check this first before trying to mount a WIM file.
PowerShell Script
You then need to open your Windows 10 Powershell ISE program and enter the below code into the editing box:
#Add your own variables below
$UpdatesPath = "D:WIMwsusoffline108wsusofflineclientw61glb*" #Path to the offline updates folder for the image OS (in this case Windows 7 x86)
$MountPath = "D:WIMMounted" #Temporary image mount folder
$WimFile = "D:WIMOriginalWin7x86Win7x86.wim" #Source of image WIM file
$IndexNumber = "1" #Image Index Number
#Start of WIM mount process
DISM /Mount-Wim /WimFile:$WimFile /index:$IndexNumber /Mountdir:$MountPath
#Start of updates injection
$UpdateArray = Get-Item $UpdatesPath
ForEach ($Updates in $UpdateArray)
{
DISM /image:$MountPath /Add-Package /Packagepath:$Updates
Start-Sleep –s 10
}
Write-Host "Updates Applied to Mount Image"
#Start of space saving on mounted image
DISM /online /Cleanup-Image /StartComponentCleanup
DISM /online /Cleanup-Image /StartComponentCleanup /ResetBase
DISM /online /Cleanup-Image /SPSuperseded
Write-Host "Image Space Saving Completed"
#Start of unmount of mounted WIM file
DISM /Unmount-Wim /Mountdir:$MountPath /commit
#Start of cleanup on WIM file
DISM /Cleanup-Wim
Alternatively, you can download the PS1 file using the button below:
Download Windows Updates Powershell Script
You should now edit the variables at the top of the script to match your own settings, ensuring that you are using the correct directory within your earlier downloaded updates for your WIM file. So, if your WIM file is Windows 7 x64, you should go to:
D:WSUSclientw61-x64glb
If your WIM file is Windows 7 x86, you should go to:
D:WSUSclientw61glb
If your WIM file is Windows 8.1 or Windows 10 x64 you should go to:
D:WSUSclientw63-x64glb
Once you are happy with all your variables, run the PowerShell script and this will then run through the following process:
- Mounts the WIM file to your temporary location
- Searches for all available updates for your WIM files
- Injects all updates into your WIM file
- Cleans up the image as much as possible included the WinSXS folder
- Unmounts the image
- Runs a WIM cleanup on the file
- Completed
Your newly updated WIM file can then be redistributed using your Configuration Manager environment.
Comments
If you have any problems with this or have any questions at all, please use our comments section below.
Share this content:
A.J., I am a little confused on your script. Lines 17,18,19,24
This article is very good, join’s a lot of other items I have read online together in one nice package, however some of your explanations on commands run in your script are misleading or incorrect.
Lines 17-19 are using the /online flag and from the documentation I have been reading at it appears that that those command will only clean up the ONLINE system ie. the computer you are currently using.
Only offline commands will alter the WIM file and to issue offline commands you must specify the source location /Image:C:MyDirMount
Once again on line 24, this actually does nothing to the WIM or image source it has already been closed and committed in the line above. This line is actually used to clean up any invalid WIM mount points. eg. If you try to commit and it fails and then running a discard fails, DISM still thinks the image is mounted, however it really isn’t. Running the /cleanup-wim just fixes the incorrect flag.
A.J., I am a little confused on your script. Lines 17,18,19,24
This article is very good, join’s a lot of other items I have read online together in one nice package, however some of your explanations on commands run in your script are misleading or incorrect.
Lines 17-19 are using the /online flag and from the documentation I have been reading at it appears that that those command will only clean up the ONLINE system ie. the computer you are currently using.
Only offline commands will alter the WIM file and to issue offline commands you must specify the source location /Image:C:MyDirMount
Once again on line 24, this actually does nothing to the WIM or image source it has already been closed and committed in the line above. This line is actually used to clean up any invalid WIM mount points. eg. If you try to commit and it fails and then running a discard fails, DISM still thinks the image is mounted, however it really isn’t. Running the /cleanup-wim just fixes the incorrect flag.
A.J., I am a little confused on your script. Lines 17,18,19,24
This article is very good, join’s a lot of other items I have read online together in one nice package, however some of your explanations on commands run in your script are misleading or incorrect.
Lines 17-19 are using the /online flag and from the documentation I have been reading at it appears that that those command will only clean up the ONLINE system ie. the computer you are currently using.
Only offline commands will alter the WIM file and to issue offline commands you must specify the source location /Image:C:MyDirMount
Once again on line 24, this actually does nothing to the WIM or image source it has already been closed and committed in the line above. This line is actually used to clean up any invalid WIM mount points. eg. If you try to commit and it fails and then running a discard fails, DISM still thinks the image is mounted, however it really isn’t. Running the /cleanup-wim just fixes the incorrect flag.