Why DISM is the Swiss Army knife of Windows 10 maintenance

command line prompt
Credit: Creative Commons via Flickr

The Deployment Image Servicing and Management command-line tool, aka DISM, has been around since Windows Vista, when it was first introduced as a method for creating and managing Windows images based on the Windows image (.wim) file format. Recently, with the introduction of the encrypted and compressed Electronic Software Download (.esd) file format in Windows 8, DISM has gained the ability to work with such files as well. In the context of the DISM utility's name, "servicing" is a broad term covering a wide range of functions that include the following:

My own recent use of DISM with Windows 10 has produced somewhat more modest tasks at which DISM is equally accomplished, but which are more likely to be of use in day-to-day system upkeep and maintenance. This list of tasks provides the basis for the remainder of this article:

Check, scan and restore Windows image health

This is definitely the DISM command collection I use most often, particularly when trying to troubleshoot flaky system components (such as "File Explorer stopped working" or "Internet Explorer stopped working," to name the two most frequent culprits). File corruption in system components can cause such flakiness, so it's wise to keep an eye on such things as part of their diagnosis. Here's an annotated listing of command-line inputs to learn more about what's going on (remember that DISM requires privileged access to do its thing, so run the CMD.exe program as administrator whenever you need to put it to work):

Dism /online /cleanup-image /checkhealth :: quick check for health status Dism /online /cleanup-image /scanhealth  :: performs detailed inspection Dism/online /cleanup-image /restorehealth [/Source <source-spec>]

The first two of these commands need little additional information or explanation, except to observe that the /checkhealth version usually completes in under five seconds and simply reports on whether or not the WinSXS files include any corrupt elements or not. The /scanhealth option makes a more detailed inspection and also logs what it finds, writing entries to the C:\Windows\Logs\CBS\CBS.log file to document any corrupt items it identifies. This also explains why the command usually takes a minute or two to complete (actual time will depend on the number of items in the WinSXS directory).

[Related: How to fix Windows 10 printing problems]

The /restorehealth option attempts to replace corrupt files in the /online component store with good, working ones available in the /Source attribute. The syntax for this source material is pretty exacting, so I'll provide and then explain an example:

/source:WIM:I:\Sources\install.wim:1

The keyword WIM identifies an image file from which to read WinSXS components. You must use this keyword verbatim, even if the source file is actually in electronic software download (.esd) format. A full file spec of the form {<drive-letter>:\<directory-path>\<filename.extension>} appears next, followed by the :1 notation to indicate that the image is the first one that appears in its container file. (One exception occurs if you've built a .wim file yourself that contains more than one image. This will almost always be applicable to downloads from Microsoft and to repair/recovery/install media. When it's not, you should be the first to know about it because you’ll have built it yourself.)

I have found the /cleanup-image /restorehealth capability to be extraordinarily useful in fixing minor Windows gotchas. I invariably turn to it for repairs before considering more drastic options, such as rolling back to an earlier restore point or performing an image reset.

Compacting the WinSXS component store

As updates are added to Windows over time, an entry gets stored in the Windows component store for each update, in addition to the components already present from the additional OS installation. This means that a certain amount of clutter is inevitable, where new components reside alongside older ones they may have made obsolete. DISM provides a way to remove such clutter, but it comes at the loss of the ability to roll back from current updates to earlier versions of the components that they replace. Nevertheless, I use this facility no less than once per calendar quarter to get rid of old stuff in the component store. Here's the DISM syntax for that command:

Dism.exe /online /cleanup-image /StartComponentCleanup /ResetBase

The StartComponentCleanup forces Windows to delete previous versions of updated components, while the ResetBase disables the ability to uninstall the most current group of updates applied to the target PC. I've recovered as much as 1.5 to 2.0 GB of disk space on some long-running OS installs after using this command (invariably, such big recoveries occur only after its first use, though).

Adding updates to Windows 10 manually

Occasionally, Microsoft will release an update that doesn't install normally on all target PCs. When that happens, especially with some kind of error code (I saw code 0x80070643 on several PCs with a recent update, KB3122947), the /add-package option in DISM can assist with getting such balky items installed. Here's the syntax:

Dism.exe /online /add-package /packagepath:<path-spec>\<file-spec>

In most cases, if you've already downloaded the update, the path specification will be C:\Windows\SoftwareDistribution\Download\ (the normal landing place for Windows Update downloads). You'll have to determine the file specification for yourself, but it will normally include the KB number as part of its name, as with the file that contained KB3122947:

Windows10.0-kb3122947-x64.cab

In most cases, putting the right /add-package directive together will get the update added quickly and easily.

Identifying Windows images and more

If you work with multiple versions of Windows, you may find yourself looking at an installer or OS image without being able to tell what's what. Though it won't work on running Windows images, DISM can tell you a fair amount about WIM and ESD files you might have laying around. Here's the syntax, on a screencap that also shows the results [see Figure 1], taken from a USB flash drive upon which I'd deposited a Windows installer without labeling it clearly enough.

dism figure 1

Figure 1.

The syntax includes a wimfile specification, followed by /index:1; both must be entered correctly (the former) or verbatim (the latter) for the command to produce the output shown. This particular output shows that it's Build 10586 of the Windows 10 Pro Technical Preview, 64-bit version. Interestingly – and this leads to the next and final item in this article – it also shows that the default language for the image is en-GB (British English)!

Identifying and changing international settings

If you want to repair a Windows image using DISM, the source material for repair and the target image must be identical (same OS, same bittedness – that is, x86 or x64, same default language). At some point in my checkered career with Windows 8, 8.1, or 10 I apparently downloaded and installed the UK language version (en-GB) on one of my machines, probably through an ill-chosen MSDN download. As I encountered mysterious problems in getting /restorehealth to work on that machine, it gradually dawned on me that my problem wasn't a lack of understanding of the DISM command (which drove me bonkers for a while). Rather, the issue was that I was trying to use an American English (en-US) image to repair a British English (en-GB) installation.

[Related: How to reduce unnecessary drivers in Windows 10]

Had I known then what I know now about DISM, I could've gotten to the bottom of things much sooner. To check the international settings for a Windows image, one uses the /Get-Intl attribute. Figure 2 is a screencap that shows both syntax and results for an online (running) image (specifying an offline image requires using the /Image attribute, with a path specification to the image file you wish to examine).

dism figure 2

Figure 2.

I discovered this discrepancy when installing an update to Windows, and observing that the keyboard behaved like a U.K. model instead of a U.S. model. This led me to change the fallback language to American English (en-U.S.) and to change my locale to the USA, after which those problems disappeared. This DISM command supports changing the installed language, but it only works on an offline image. To make that change, I'd have to boot to a recovery image, then navigate to the installed image file on this machine, and perform a series of commands involving /Set-UILang, /Set-UILangFallback, /Set-UserLocale, and /SetInputLocale (see TechNet for all those details).

Even more blades and widgets

Although these examples encompass a fair number of capabilities in DISM, it's just the beginning of what you can do with this powerful and capable tool. The more you dig into it, the more you'll find to like about it. That's why the Technical Reference on DISM at TechNet should be on your favorites list or in your browser bookmarks. You can also find lots of great, step-by-step tutorials on working with DISM at TenForums.com, especially "How to Repair Windows 10 Image using DISM." Enjoy!

NEW! Download the State of the CIO 2017 report