:: BATCH SCRIPT START
@ECHO OFF
SETLOCAL EnableDelayedExpansion
SET InputFile=Machines.txt
SET OutputFile=RestartStatus.txt
IF NOT EXIST "%InputFile%" ECHO "%InputFile%" file does not exist. &GOTO :EndScript
FOR %%R IN ("%InputFile%") DO IF %%~zR EQU 0 ECHO "%InputFile%" file is empty. &GOTO :EndScript
IF EXIST "%OutputFile%" DEL /F /Q "%OutputFile%"
FOR /F %%c IN ('TYPE "%InputFile%"') DO (
ECHO Processing: %%c
PING -n 1 -w 1000 %%c|Find /I "TTL" >NUL
IF NOT ERRORLEVEL 1 (
ECHO Restarting %%c >>"%OutputFile%"
SHUTDOWN /m \\%%c /r /t 0
)ELSE (ECHO Unable to connect %%c: system may be offline.))
ECHO. &ECHO Script complete. Check "%OutputFile%" file.
:EndScript
ENDLOCAL
EXIT /B 0
:: BATCH SCRIPT END
|