Example: CMD or BAT For Loop

Example: CMD or BAT For Loop

Kam Salisbury

@ECHO OFF

rem *** REQUIRES computers.txt, 1 computer name per line, no blanks or comments

rem *** Create a variable for date stamping saved report files

For /f "tokens=1,2,3,4,5 delims=/. " %%a in ('date/T') do set CDate=%%d-%%b-%%c


rem *** Log start date and time

echo Start! %date% - %time% >> OSTs_Log_%CDate%.txt

echo Start! %date% - %time% >> OSTs_DeviceNOTfound_Log_%CDate%.txt


rem *** Read the queue of computer names

FOR /F %%i IN (Computers.txt) DO (

              rem * Check if computer online

              ping -n 1 %%i | find "TTL=" >nul

              rem * If computer not online, log it and process next

              IF errorlevel 1 (

                             echo %%i >> OSTs_DeviceNOTfound_Log_%CDate%.txt

                             echo %%i NOT ready

              ) ELSE (

                             rem * If computer is online, map drive, look for OST files, process next

                             echo %%i ready, processing...

                             echo %%i >> OSTs_Log_%CDate%.txt

                             net use x: \\%%i\c$\users /persistent:no

                             dir x:\*.ost /s /n >> Dell_OSTs_Log_%CDate%.txt

                             net use x: /delete

              )

)


echo Done! %date% - %time% >> OSTs_Log_%CDate%.txt

echo Done! %date% - %time% >> OSTs_DeviceNOTfound_Log_%CDate%.txt

echo Done!