Link to home
Start Free TrialLog in
Avatar of bbcac
bbcac

asked on

Ping Script or Batch File

I am looking for a VBScript or BAT file that can ping a list of computers and output the results to a text file.
Avatar of SteveGTR
SteveGTR
Flag of United States of America image

You could create a file named server.txt that has a line for each server. Name the file servers.txt. For example:

server1
server2
server3

Here's batch file that will ping each and save the results to a file named output.txt:

@echo off

setlocal

set serverFile=server.txt
set outFile=output.txt

if not exist "%serverFile%" echo %serverFile% does not exist.&goto :EOF

del "%outFile%" 2>NUL

for /f "tokens=*" %%a in ('type "%serverFile%"') do call :PROCESS "%%a"

echo Results in %outFile%

goto :EOF

:PROCESS

(echo Processing %~1)>>"%outFile%"
(echo ---------------------)>>"%outFile%"

ping %~1 >>"%outFile%"

goto :EOF

Good Luck,
Steve
Avatar of bbcac
bbcac

ASKER

that doesn't seems to work... here is my output file

Processing aComputerName
---------------------
Results in output.txt


where aComputerName is an actual comptuer
I didn't initially test the code, just wrote it. It amazingly works as posted. I tested at work where SERVER.TXT has two computers in it:

server1
server2

The output showed the ping output.

Did you cut and paste the code above?

Does the processing display any other information to the console when it runs?

What happens if you say this from the command line?

ping aComputerName

Where aComputerName is an actual computer.
ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
bbcac, have you looked at any of the Experts possible solutions here?

Rob.