Simple & Cool Batch file to ping Multiple Computers from a Text File

I came across as a simple and very nice batch script from Technet site. It is really great. It gives a clean output.

@echo off
set fnm=C:\Scripts\computers.txt
set lnm=C:\Scripts\pingresult.txt
if exist %fnm% goto Label1
echo.
echo Cannot find %fnm%
echo.
Pause
goto :eof
:Label1
echo PingTest STARTED on %date% at %time% > %lnm%
echo ================================================= >> %lnm%
echo.
for /f %%i in (%fnm%) do call :Sub %%i
echo.
echo ================================================= >> %lnm%
echo PingTest ENDED on %date% at %time% >> %lnm%
echo … now exiting
goto :eof
:Sub
echo Testing %1
set state=alive
ping -n 1 %1
if errorlevel 1 set state=dead
echo %1 is %state% >> %lnm%

*** Create 2 files computers.txt & Pingresult.txt in c:\scripts folder or any where you like and change accordingly in the script

Source: http://social.technet.microsoft.com/Forums/en/ITCG/thread/c0cafc24-c9be-4f67-ada0-4bb05fb26e78

Leave a Reply