::Checks all drives, tested and works on flash drives and hard disks.
::Network drives to do get checked or create errors, chkdsk cannot check network drives, only physical
::Works on OS's that have fsutil, including windows xp and server 2003 and above
::Makes a list of all the drive letters used on the system
FOR /F "skip=1 tokens=1,2 delims=:\ " %%A IN ('FSUTIL FSINFO DRIVES ^| MORE
/E /T0') DO (
IF "%%B"=="" (
SET Drives=!Drives! %%A
) ELSE (
::Checks every drive through normal chkdsk and makes report of output from chkdsk
FOR %%A in (%Drives%) DO chkdsk %%A: > ChkDskReport%%A.txt
::echo CHKDSK cannot continue in read-only mode. > ChkDskReportC.txt
::For all the drives, check to see if any errors occured / needs to chkdsk /f
FOR %%A in (%Drives%) DO CALL :Check %%A
::Final Report, condenses any error reports into one
FOR %%A IN (%Drives%) DO IF EXIST ChkDskReport%%A.txt CALL :Report %%A
::checks to see if errors occured, if so acts on it
::Searches for string concerning errors in report
FOR /f "tokens=*" %%a IN ('find "CHKDSK cannot continue in read-only mode." ChkDskReport%1.txt') DO SET test=%%a
::if file has the string concerning errors, report on it or do other action, right now it echo's
IF ("%test%") neq ("---------- CHKDSKREPORT%1.TXT") (
ECHO run %test% Drive %1
) ELSE (
::if report has no errors, or is about drive that is not physical, delete report
::is there a better way, so that GOTO's don't have to be used?
::Makes final report file, with Date, Drive Letter, and chkdsk report, ends with newline.
DATE /t >> ChkDskReport.txt
ECHO Drive %1 >> ChkDskReport.txt
TYPE ChkDskReport%1.txt >> ChkDskReport.txt
echo. >> ChkDskReport.txt
::end of file
RichCI was able to get the batch file to work correctly by running the file under execute shell command. This was the last step - copied the file to the destination, then ran the file under shell command and the information was written to a file in a shared location. I hope this helps.