Every admin knows the usage of Deployment Image Servicing and Management (DISM) for mounting and customizing Windows images. DISM is a comprehensive and varied utility, providing many lesser-known capabilities around servicing applications and drivers, applying unattend.xml, changing your Windows edition, or even reverting Windows to a previous OS installation.

The DISM command is known for working with Windows images and FFU files, and can even be used for working with VHD and VHDX disks for services. It is built into Windows and can be called from the command line, Windows PowerShell, and PowerShell Core.

It is important to note that the DISM.exe command line tool and DISM PowerShell cmdlets have corresponding functionalities. However, you can also call the DISM.exe tool from a PowerShell environment. Microsoft has a good comparison between the DISM.exe command line options and PowerShell's equivalent cmdlets.

Running the DISM command and exploring the options

Running the DISM command and exploring the options

The functionality provided by DISM allows IT admins to perform servicing tasks that fall within two main use cases:

  • Servicing the image itself: Admins can configure and customize the .wim image, including adding and removing drivers, configuring language settings, adding or removing Windows features, and even changing the Windows edition.
  • Managing the data in the Windows image: Using DISM, you can inventory the image components, drivers, and updates, split the image, and delete or add images within a .wim file.

Remember that DISM can only service images for operating system versions equal to or older than the currently installed version of DISM. In addition, it always requires a session with elevated permissions, even to show the online help.

Mounting and servicing a WIM

DISM is primarily used to capture and restore images of Windows machines for subsequent mass rollout to devices. You can also use DISM for deployment with Microsoft Deployment Toolkit (MDT). Conversely, it can also service images captured with MDT.

Mounting, servicing, and unmounting a WIM comprise the following commands (in this example, we add a language pack to the image):

dism /Mount-Wim /MountDir:mount /wimfile:boot.wim /index:1
dism /image:mount /Add-Package /PackagePath: "e: \lp.cab"
dism /Unmount-Wim /MountDir:mount /commit

If you want to apply the changes to the images, use /Discard instead of /commit when unmounting. You can save changes to the WIM file without unmounting it using this command:

DISM.exe /Commit-Image /MountDir:mount

Capturing an image

You can capture Windows images using a command like this:

Dism /Capture-Image /ImageFile:install.wim /CaptureDir:D:\ /Name:Drive-D

To apply a Windows image to a device, use the following:

Dism /apply-image /imagefile:N:\Images\my-windows-partition.wim /index:1 /ApplyDir:W:\

Adding and removing drivers

If you are deploying the same image across multiple hardware configurations, the reference image may not contain all the drivers needed to cover the different vendor hardware. DISM has you covered with the ability to add drivers to the offline Windows image. In the example below, you can add all the needed drivers to a folder and recursively add the drivers it contains to the Windows image.

Dism /image:C:\test\offline /Add-Driver /driver:C:\test\drivers /recurse

You can also remove drivers using DISM:

Dism /image:C:\test\offline /Remove-Driver /driver:oem1.inf

Lesser-known capabilities of DISM

Note the following capabilities of DISM that are not so apparent and can be used for a wide range of operations:

  • Set the system user interface (UI) language.
  • Set the input locale and keyboard layout.
  • Set the time zone in the Windows image.
  • Get target Windows edition information, and change the Windows edition.
  • Add and remove drivers.
  • Update packages or other services using an unattend.xml answer file.
  • Revert a PC to a previous Windows installation, and remove previous Windows versions.
  • Repair Windows images and VHD/VHDX files.
  • Manage AppX and install MSU files.
  • Add or remove optional features.
  • Manage file associations.

Set the system user interface language

Using DISM, you can manage and set the system user interface (UI) language for a Windows image. Let's say you had taken a reference Windows image for deployment. If you have multiple locations where you want to deploy the image, instead of having to capture a reference image from scratch, you can use DISM to change the UI language for each location.

Dism /image:C:\test\offline /Set-SysUILang:en-US

Set the input locale and keyboard layout

DISM allows changing the input locale and keyboard layout, which, again, is useful if you need to do so for an offline image without recapturing it before deployment.

Dism /image:C:\test\offline /Set-InputLocale:fr-fr
Dism /image:C:\test\offline /Set-InputLocale:0410:00010410

Set the time zone in the Windows image

You can set the time zone for an offline image, allowing the servicing of images to customize the time zone of a captured image before deploying it to multiple time zones.

Dism /image:C:\test\offline /Set-TimeZone"Central Standard Time"

None of the above commands can be applied to a live system because the international provider doesn't support the /online switch.

Getting and changing the Windows edition

Suppose you want to check the available Windows editions that can be targeted for a specific Windows image (online and offline):

Dism /Image:C:\test\offline /Get-TargetEditions
Show available Windows edition for the current system

Show available Windows edition for the current system

To change the Windows edition to a higher target edition, you need to use the /AcceptEula switch and enter a product key to unlock the higher edition of Windows.

Dism /online /Set-Edition:<edition name> /AcceptEula /ProductKey:12345-67890-12345-67890-12345

Update packages or other services using an unattend.xml answer file

Much like using an unattend.xml file when installing Windows, you can use the unattend.xml file to update software packages and services using DISM.

Dism /image:C:\test\offline /Apply-Unattend:C:\test\answerfiles\myunattend.xml

Revert a PC to a previous Windows installation

DISM also allows you to manage Windows versions and revert to different versions of Windows. To revert to a previous version of Windows, you can use the following command:

DISM /Online /Initiate-OSUninstall [/NoRestart|/Quiet]

Remove previous Windows versions

If you want to remove the ability to revert to a previous version of Windows and free up space, DISM can delete the dispensable OS:

DISM /Online /Remove-OSUninstall

Repair Windows images and VHD/VHDX files

One of the handy features of DISM is its ability to repair Windows online and offline images, as well as VHD/VHDX files. You can scan a Windows image or VHD/VHDX file for corruption with the following:

Dism /Online /Cleanup-Image /ScanHealth
Check system integrity with DISM

Check system integrity with DISM

To check for any corruption detected and clean up the image, you can use the following:

Dism /Online /Cleanup-Image /CheckHealth

To repair an image, you can use the following:

Dism /Image:C:\offline /Cleanup-Image /RestoreHealth /Source:c:\test\mount\windows
Dism /Online /Cleanup-Image /RestoreHealth /Source:c:\test\mount\windows /LimitAccess

Manage AppX and install MSU files

DISM is able to manage app packages (.appx or .appxbundle) and operating system packages (CAB or MSU files). So, you can avoid recapturing a reference image.

Manage provisioned AppX packages

Get provisioned AppX packages:

Dism /Image:C:\test\offline /Get-ProvisionedAppxPackages

Add provisioned AppX packages:

dism.exe /Add-ProvisionedAppxPackage {/FolderPath:<App_folder_path> [/SkipLicense\] [/CustomDataPath:<custom_file_path>]  /PackagePath:<main_package_path> [/DependencyPackagePath:<dependency_package_path>] {[/LicensePath:<license_file_path>] [/SkipLicense\]} [/CustomDataPath:<custom_file_path>]} [/Region:<region>]

Remove the AppX package

Dism /Image:C:\test\offline /Remove-ProvisionedAppxPackage /PackageName:<PackageName>

Add and remove packages

DISM can also be used to manage operating system packages with CAB or MSU files:

Dism /Image:C:\test\offline /Get-Packages

Add a package to a Windows image:

Dism /Add-Package /PackagePath:<path_to_cabfile> [/IgnoreCheck] [/PreventPending]

Remove a package:

Dism /Image:C:\test\offline /LogPath:C:\test\RemovePackage.log/Remove-Package {/PackageName:<name_in_image> | /PackagePath:<path_to_cabfile>}

Add or remove optional and on-demand features

Another great DISM capability is managing optional features in your online and offline images.

To find the installed Windows features in an image, you can use the following:

Dism /online /Get-Features
Dism /Image:C:\test\offline /Get-Features

To add Windows features (e.g., TFTP), use the following:

Dism /online /Enable-Feature /FeatureName:TFTP /All
Dism /Image:C:\test\offline /Enable-Feature /FeatureName:TFTP /All

To remove Windows features:

Dism /online /Disable-Feature /FeatureName:TFTP
Dism /Image:C:\test\offline /Disable-Feature /FeatureName:TFTP

Microsoft calls feature packages either optional features or features on demand, although the distinction between these two is unclear. This command shows all available capabilities, present as well as not present:

Dism /online /Get-Capabilities

To install the RSAT tool for WSUS, you use the utility as follows:

Dism /online /Add-Capability /CapabilityName:Rsat.WSUS.Tools~~~~0.0.1.0
Install RSAT for WSUS using DISM

Install RSAT for WSUS using DISM

To remove it, use /Remove-Capability instead of /Add-Capability.

Manage file associations

DISM can define which application opens a specific file type (file associations) for both online Windows installations and offline images.

If you have a source machine from which you want to export the file associations, you can do that with DISM:

Dism.exe /Online /Export-DefaultAppAssociations:C:\AppAssoc.xml
Export file associations to an XML file

Export file associations to an XML file

You can then take the exported XML file and import the file to a new target machine or image:

Dism.exe /Online /Import-DefaultAppAssociations:C:\AppAssoc.xml
Dism.exe /Image:C:\test\offline /Import-DefaultAppAssociations:C:\AppAssoc.xml

You can also use XML with group policies if you want to apply it to many PCs.

Wrapping up

The DISM command-line utility allows IT admins to perform all sorts of tasks and operations on Windows images and virtual hard disks. It is generally used with the typical duties of capturing, applying, and mounting Windows images.

Subscribe to 4sysops newsletter!

However, DISM has many capabilities that admins may not be aware of. As shown, you can perform operations on applications, drivers, Appx packages, and operating system packages. In addition, they can change the input locale, time zone, and keyboard layout, and even control the Windows edition, control file associations, repair images and VHD/VHDX files, and roll back to previous Windows installations.

avataravataravatar
4 Comments
  1. bgavin 8 months ago

    DISM, can also be fragile. There are commands to check its state.

    DISM /online /Cleanup-Image /ScanHealth
    DISM /online /Cleanup-Image /SpSuperseded
    DISM /online /Cleanup-Image /StartComponentCleanup
    DISM /online /Cleanup-Image /RestoreHealth

  2. “If you want to apply the changes to the images, use /Discard instead of /commit when unmounting”.
    I guess this statement requires correction. Great article by the way.

  3. Interesting article, thanks to share it.

  4. Allan 8 months ago

    Good info. I wanted to know about DISM as a non-sysop. Keep the articles coming.

Leave a reply

Please enclose code in pre tags

Your email address will not be published.

*

© 4sysops 2006 - 2023

CONTACT US

Please ask IT administration questions in the forums. Any other messages are welcome.

Sending

Log in with your credentials

or    

Forgot your details?

Create Account