How to ping multiple hosts and save result in a test file

2

First, put all of your server names into a text file with each server name on a separate line. Let's call it "servers.txt" and save it (as you going to ping server names so make sure name resolution is happening).

Next, open Command Prompt and navigate to the folder where you just created the file in which you listed the name of servers.

Now, enter the following line on the command prompt:

for /f "tokens=1" %a in (servers.txt) DO @ping -n 1 %a

This will attempt to ping every system in the list and return the result.
If you want to save the ping results, use this instead,

for /f "tokens=1" %a in (servers.txt) DO @ping -n 1 %a >> PingResults.txt

The above script only sends one ICMP packet to each server you list. Now, that’s probably good for just seeing if the server is accessible or not. You may want to increase the number of ICMP packets sent to each server. You can do that by changing the value after -n.

You can also modify the ping command at the end of the command above as needed with options pertaining to ping.

or Using PowerShell

Test-Connection server1, server2, etc, | Out-File C:\PingResults.csv

Or do it this way to get the list of servers

$Computers = Get-Content C:\Computerlist.txt
Test-Connection $Computers | Out-File C:\PingResults.csv

That's it.......... 🙂

Share.

About Author

My name is Noor Mohammad. I have around 7 years of IT experience and currently working with an MNC as a VMware SME. I am a VCP5-DCV and have other certifications like VCA-DCA/WM/Cloud, MCSE, MCTS & ITIL-Foundation etc. For my contribution towards VMware community, VMware has awarded me as VMware vExpert in 2015 & 2016 .... :) For more VMware infrastructure related posts, you may visit my blog at http://noor2122.blogspot.in/

2 Comments

Leave A Reply