Creation of a Basic batch file tp generate ping output

I need to create a batch file that will ping in excess of 25 IP addresses and generate output to a .txt file.  I'm sure this is a nice easy one for someboy to answer.  I have already tried running the command below but am prompted with the message C:\Computers.txt was unexpected at this time.  I'm sure this is something very simple..

For /f %a in C:\Computers.txt do ping %a -n 2 >> C:\Ping_Results.txt
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

use %i instead of %a
OGLEDAuthor Commented:
Have tried %i instead of %a but the same error message occurs (C:\Computers.txt was unexpected at this time).  

Any other suggestions?
try this one -
for /f %i in (C:\Computers.txt ) do ping %i >> C:\Ping_Results.txt
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

OGLEDAuthor Commented:
I am now prompted with the message:  The System cannot find the file C:\Computers.txt.  
Obviously I am 100% sure that c:\computers.txt exists.
please verify the filename (spelling) again
also check that you have not checked "Hide extensions for known file types" in folder options - view
sometimes your filename becomes computers.txt.txt
please verify this also
OGLEDAuthor Commented:
Ok were making progress, thanks.  The file extensions were not displayed, schoolboy error on my part.

My overall requirement is as follows:
We have 25 network devices that we want to ping every 15 minutes so we can measure the response in milliseconds over a 24hr period.  I suspect the best way to do this is to create a scheduled task that calls the ping batch file every 15 minutes.  I want each ping to append the data to the same log file and provide a date / time stamp so our network guys can do some analysis around why the response is slower at specific intervals in the day.  

Obviously the desired solution would be to implement qos so we can prioritise network traffic / allocate bandwidth utilisation but we are some way from achieving this.  We are also in the process of implementing HP's NNM (network node manager) which would also asist with this type of troubleshooting.
yes use scheduled task to run a script to run this command and to append the result file so that you will not loose previous result files
OGLEDAuthor Commented:
The C:\Ping_Results.txt file does not contain a date / time stamp for when the command was ran?  
Any ideas? Sorry to be a pain but need to get this working tonight if possible.
Lee W, MVPTechnology and Business Process AdvisorCommented:
First %i or %a doesn't matter.  either can be used - that's not the problem.  You're running this in a batch file, right?  Well, in a batch file, when using the for command, you need to double the % signs.  In addition you need to put the file name in parens.

For /f %%a in (C:\Computers.txt) do ping %%a -n 2 >> C:\Ping_Results.txt

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Lee W, MVPTechnology and Business Process AdvisorCommented:
So to reiterate:

In a batch file:

As a single command on the command line:
To add the date and time is not difficult.  


time /t
This will give the time.

date /t  -- this will give the date.  

Add those commands to run before your ping in the batch file (with the output piped to your file) and you should be all set.
I suggest that to log the date/time, just change the dos prompt to display the date and time.
This way, you will see the updated date/time on every line.

eg. add this line to the first line in your batch file
prompt $d $t

try it and see the result! :)
Lee W, MVPTechnology and Business Process AdvisorCommented:
Actually, it's easier still - you can use %date% and %time% to display the date and time:

For /f %%a in (C:\Computers.txt) do (
   echo %date% %time%>>c:\Ping_Results.txt
   ping %%a -n 2 >> C:\Ping_Results.txt
therefore your batch looks like -

date /t >> C:\Ping_Results.txt
time /t >> C:\Ping_Results.txt
For /f %%i in (C:\Computers.txt) do ping %%i -n 2 >> C:\Ping_Results.txt
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.