Script is needed to ping the servers by name and output the server names with their IPs into csv.

Hello,
I need a script that pings the servers by name using inputfile with servernames, and then outputs the server names with their IPs into csv.

Thank you very much!
creative555Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

Randy DownsOWNERCommented:
Try this

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

Open in new window



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
[code]

$Computers = Get-Content C:\Computerlist.txt

Test-Connection $Computers | Out-File C:\pingresults.csv

Open in new window

creative555Author Commented:
Hi,
I was wondering if it is possible to produce a cleaner output - just one line - per server name.

Below is the output for one server listed 4 times. Also, could you please add the line for the servers that dont respond to be listed as well in the output as "down" or Not responding...etc

Thank you so much.

------      -----------      -----------      -----------      -----      --------
USWESWNE3I...      NYC-FNGFIPR01      10.42.30.16             32      98
USWESWNE3I...      NYC-FNGFIPR01      10.42.30.16             32      114
USWESWNE3I...      NYC-FNGFIPR01      10.42.30.16             32      105
USWESWNE3I...      NYC-FNGFIPR01      10.42.30.16             32      107
Randy DownsOWNERCommented:
Maybe this will work. I added "n" (newline) after $Computers

$Computers = Get-Content C:\Computerlist.txt

Test-Connection $Computers "n" | Out-File C:\pingresults.csv
[code]

$Computers = Get-Content C:\Computerlist.txt

Test-Connection $Computers | Out-File C:\pingresults.csv

Open in new window

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
creative555Author Commented:
Thank you so much! Actually it exports one line per server. Excellent!
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
Powershell

From novice to tech pro — start learning today.