Files
management-scripts/Fix-WindowsHealth.bat
T

34 lines
1.4 KiB
Batchfile
Raw Normal View History

2019-11-11 19:22:39 -05:00
@echo off
rem ## Scan the Windows Component Store for problems
dism /online /cleanup-image /scanhealth >nul
rem ## Check to see if the previous command recorded any problems that need repairing
rem ## If there aren't any problems, jump to the section labeled skip-restorehealth
dism /online /cleanup-image /checkhealth | find /i "repairable" >nul || goto :skip-restorehealth
rem ## If there are problems with the Windows Component Store, repair them
rem ## Once the repair operation completes, jump to the section labeled run-sfc
dism /online /cleanup-image /restorehealth >nul
rem ## If the Windows Component Store gets repaired, the Ninja activity feed will
rem ## see the following line:
echo The component store has been repaired.
goto run-sfc
rem ## This scetion only runs if there aren't any problems to repair
:skip-restorehealth
rem ## If the Windows Component Store is healthy, the Ninja activity feed will
rem ## see the following line:
echo No component store corruption detected.
rem ## This section runs the sfc utility
:run-sfc
rem ## Check to see if the TrustedInstaller is running, if not then start it
rem ## This avoids a common problem with sfc not starting
sc query trustedinstaller | find /i "running" >nul || net start trustedinstaller >nul
rem ## This will take a while and the output of sfc will be recorded in a text file
sfc /scannow > %SystemDrive%\sfcoutput.txt