Windows Health (Checking/Restoring)

Checking and Restoring Windows Health

Check the Disk

chkdsk c:
REM use the /f option to force fix any errors
chkdsk c: /f

c:\Windows\System32>chkdsk c: /f
The type of the file system is NTFS.
Cannot lock current drive.

Chkdsk cannot run because the volume is in use by another
process.  Would you like to schedule this volume to be
checked the next time the system restarts? (Y/N) y

This volume will be checked the next time the system restarts.

System File Check

REM Running the below should start to repair Windows
sfc /scannow

REM If you run into the error (Windows Resource Protection could not start the repair service.) Try the below and then run sfc /scannow again.
sc config trustedinstaller start= auto
net start trustedinstaller

DISM from within Windows

REM Run the commands in the following order
dism /online /cleanup-image /scanhealth  
dism /online /cleanup-image /checkhealth  
dism /online /cleanup-image /restorehealth

DISM from safe mode

Note: find the drive that Windows is installed on and then run the below commands.
Replace E:\ with the actual drive letter Windows is installed on.

dism /image:E:\ /cleanup-image /scanhealth
dism /image:E:\ /cleanup-image /checkhealth
dism /image:E:\ /cleanup-image /restorehealth

REM if you boot from a USB drive and need to specify a scratch disk use the below
dism /image:E:\ /cleanup-image /scanhealth /scratchdir:E:\temp

DISM when you need to specify a source

REM Use the below 2 to return the correct index for the edition of Windows that you will be using.
Dism /Get-WimInfo /WimFile:D:\sources\install.wim
Dism /Get-WimInfo /WimFile:D:\sources\install.esd

REM Use the below commands to repair the image, be sure to double check the index
Dism /Online /Cleanup-Image /RestoreHealth /source:wim:D:\sources\install.wim:1 /limitaccess
Dism /Online /Cleanup-Image /RestoreHealth /source:ESD:D:\sources\install.esd:6 /limitaccess

DISM Reverting Pending Update Actions

Dism /image:E:\ /cleanup-image /revertpendingactions /scratchdir:E:\temp

DISM commands that will clean up the WinSxS folder and remove any unnecessary files

dism.exe /online /Cleanup-Image /StartComponentCleanup
dism.exe /online /Cleanup-Image /SPSuperseded