DISM and SFC are both tools built into modern Windows systems which can be used to fix a large number of issues. This article is only going to cover some of the basics for DISM, so keep that in mind. The features we are going to cover with DISM are only included on Windows 8 and newer. SFC has been around forever pretty much, but still remains useful for newer Windows builds because of the constant upgrades it has received. These tools are extremely useful for fixing common Windows Update issues.
SFC
SFC is the System File Checker. In order to invoke it for the most common scenarios, you want to run this command from an admin command prompt:
sfc /scannow
SFC can take a bit to run, but it will try to restore the health of the machine by repairing files from a cache it keeps. This is not always going to be the best type of repair, but it is the only easy, online method on Windows 7 (Server 2008 R2) or older, and it can fix certain issues that DISM may not be able to on newer Windows systems. SFC creates a log under C:\Windows\Logs\CBS\CBS.log (or wherever the Windows directory is) which contains a lot of information about what CBS has done and what it has found. You may see SFC tell you everything is fine, but it may not be unless the log is clean.
DISM
DISM is way more powerful than SFC. DISM usually works much better and can restore files that SFC can’t. Basically, if Windows Update works, DISM will work. There are exceptions to this for more exotic cases, but this is the typical rule of thumb I have seen. DISM cannot fix certain classes of issues either, even though many people sell it and SFC as a panacea. To run DISM to restore the health of a machine you run the following from an admin command prompt:
dism /online /cleanup-image /restorehealth
DISM also creates a log, though it is not really as useful as the log for SFC. The CBS log will be populated to some degree, as will C:\Windows\Logs\DISM\DISM.log or wherever the Windows log is. Depending on the extent of the corruption, you may need to run DISM in conjunction with SFC and reboot. I have seen instances where after a reboot you need to run it a few more times to fix an issue as well.
DISM for Space
DISM does include some other options to cleanup certain components in the Side By Side (SXS) folder. One is safe to run after most updates, and one is not. To safely clean out components in most scenarios you can run:
dism /online /cleanup-image /startcomponentcleanup
DISM has a mode to reset the OS base (I am not including it here due to how dangerous it can be). This option is almost never what you want unless you know why you want it. This may sound like a typical IT cop out phrase, but in this case, it very much is true.
Advanced DISM Rescue
DISM has some other ways to clean up and repair an image. These typically are reserved for when an agent is not able to just be wiped or reinstalled because it is a production machine or similar. The three main methods for this are to either: do this live on the machine from a cached file source (like an installation DVD or similar), do this from an installation media environment or recovery mode, or to do this from another copy of Windows as a source (either live or from a recovery environment).
If you run into dism /online /cleanup-image /restorehealth and sfc /scannow just plain not working over and over, you can try to mount your install media somewhere like D:\Installation and run something like the following from an admin command prompt:
dism /online /cleanup-image /restorehealth /source:WIM:D:\Installation\sources\install.wim:1 /limitaccess
This will basically use the WIM file to try and restore components to Windows while live. The /limitaccess prevents this from failing while trying to download from Windows Update in case that is too broken to work. You may get something like ERROR: 0x800f081f … The source files could not be found. In this case, read the dism log to look for either errors or try and continue run sfc /scannow and dism /online /cleanup-image /startcomponentcleanup. You can also try running the commands without /limitaccess again to see if it will help.
DISM from Recovery
Trying this process from an installation media or recovery environment is a great way to usually ensure this process will work, but it does require being physically in front of the machine. Make sure to use the same installation version and build as the version of the OS on the machine. You will need to have the mount locations for the installation media itself and the drive with the OS you want to fix. Assume you have booted off of D: where your installation media is and the drive with the OS you want to fix is Z:. You can get the mount points by running diskpart then running list volume. If the drive isn’t mounted, you will need to mount it. You should also make a temporary, scratch directory for this process, something like mkdir Z:\temp. You should run the DISM command with something similar to one of the following:
dism /image:Z: /cleanup-image /restorehealth /scratchdir:Z:\tmp /limitaccess
dism /image:Z: /cleanup-image /restorehealth /scratchdir:Z:\tmp /source:WIM:D:\sources\install.wim:1 /limitaccess
You can also do this from another copy of Windows. This is a messy method, but it can be very useful in environments where you cannot do the previous method, or the previous methods just won’t work. This method requires a live system on the network where you can access the Windows directory remotely (admin share or a share otherwise). You can also theoretically do this from an installation media (even different versions sometimes) with the right setup. The syntax would be something like:
dism /image:Z: /cleanup-image /restorehealth /scratchdir:Z:\tmp /source:WIM:D:\sources\install.wim:1 /limitaccess
This document is obviously in no way an exhaustive list of all of the features of DISM, but it is a great place to jump off for restoring machine health in a way which can either be automated in scripts, or done remotely without just resorting to reimaging a machine whenever something goes wrong. DISM and SFC both can be used in conjunction in order to rule out certain classes of issues and can work together to fix issues that neither could do separately.
Still Stuck?
See here for more information on fixing these issues in Windows 10 and similar.