Advanced Windows System Cleanup Commands â€“ SFC and DISM.
I recently ran into some problems with one of my Windows Server installations that was behaving relatively strangely. Big surprise, right? After digging around, I came up with a complete set of commands that check the health of the system and fix any damage that might have occurred to the system files.
Feel free to run them in the order below if your system has stability issues or other weird and frustrating issues.
SFC / scannow
Also known as the System File Checker, this classic command checks Windows system files for corruption and repairs corrupted files. This is the first tool we always run to check the integrity of the system and try to fix them automatically.
DISM / Online / Image Cleanup / ScanHealth
This tool is used when the SFC does not detect any damage or is not very helpful in fixing the problem. With DISM, we can serve up an offline Windows image (WIM), VHD file or online Windows image.
The / ScanHealth switch scans the online image for damage and determines if there is any problem.
DISM / Online / Cleanup-Image / CheckHealth
After executing the first command, we need to execute the same command with the “/ CheckHealth” parameter to see if any damage was detected. After the completion of the command, it will inform you whether the image is working properly, is subject to repair or beyond repair.
DISM / Online / Cleanup Image / RestoreHealth
If we find that the image is corrupted, we will run the same command with the / RestoreHealth switch, which will automatically fix any damage. This may take about twenty minutes.
DISM / Online / Cleanup-Image / SPSuperseded
This optional / SPSuperseded parameter removes all superseded updates and service packs from the Winsxs folder to free up space on systems that have low disk space on the OS drives.
Hopefully, the performance and stability of your system improves after running the above commands. Enjoy!