?
Solved

Powershell script to ping a list of IP address and output to file

Posted on 2015-02-06
12
Medium Priority
?
13,840 Views
Last Modified: 2015-02-06
Per the title, I need a simple script to ping a list of IP addresses. If it helps, I am pinging a list of printers. But I would like to be able to use this for other systems as well.

Any how, I have a text file which contains a list IP's. I simply want ping output to display whether the host is online or not ( icmp replies or timeouts)

many thanks
0
Comment
Question by:tobe1424
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
12 Comments
 
LVL 40

Expert Comment

by:Subsun
ID: 40593847
Here is a sample code which will read a text file and display the server status on console..
GC C:\Temp\Server.txt | %{
	If (Test-Connection $_ -Quiet -Count 2){
	Write-Host "$_ is UP" -b Green
	}
	Else{
	Write-Host "$_ is Down" -b Red
	}
}

Open in new window

1
 

Author Comment

by:tobe1424
ID: 40593850
Thanks much! Let me give that a shot
0
 
LVL 40

Assisted Solution

by:Subsun
Subsun earned 2000 total points
ID: 40593856
With small modification, you can save result in to a file..
GC C:\Temp\Server.txt | %{
	If (Test-Connection $_ -Quiet -Count 2){
	"$_ is UP"
	}
	Else{
	"$_ is Down"
	}
} | Out-File C:\Temp\result.txt

Open in new window

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:tobe1424
ID: 40593863
I like how the script operates...pretty cool. However, they appear to be "down" when in fact I can ping some of the addresses in my list

powershell output
0
 
LVL 40

Expert Comment

by:Subsun
ID: 40593867
You can remove the  parameter -Count 2 and try..
0
 

Author Comment

by:tobe1424
ID: 40593869
This is the output from the same pc.

Pinging 172.24.20.36 with 32 bytes of data:
Reply from 172.24.20.36: bytes=32 time<1ms TTL=60
Reply from 172.24.20.36: bytes=32 time<1ms TTL=60
0
 

Author Comment

by:tobe1424
ID: 40593871
let me try
0
 

Author Comment

by:tobe1424
ID: 40593877
Thanks for prompt help. i removed the parameter..but it still shows red. They are printers, not servers. However, its just an IP we are talking about here so I am dumbfounded
0
 
LVL 40

Expert Comment

by:Subsun
ID: 40593889
What is the result for
Test-Connection 172.24.20.36 

Open in new window

0
 

Author Comment

by:tobe1424
ID: 40593898
Seems to be working


Source        Destination     IPV4Address      IPV6Address                              Bytes    Time(ms)
------        -----------     -----------      -----------                              -----    --------
MYHOST 172.24.20.36    172.24.20.36     {}                                       32       0
MYHOST 172.24.20.36    172.24.20.36     {}                                       32       1
MYHOST 172.24.20.36    172.24.20.36     {}                                       32       0
MYHOST 172.24.20.36    172.24.20.36     {}                                       32       0
1
 
LVL 40

Accepted Solution

by:
Subsun earned 2000 total points
ID: 40593909
ok.. Probably your input file have trailing space for IP addresses. Change the second line to..
	If (Test-Connection $_.Trim() -Quiet -Count 2){

Open in new window

1
 

Author Comment

by:tobe1424
ID: 40593946
Yes this is a preview from my input file:

172.24.20.36
172.24.20.42
172.24.12.34
172.24.20.24
172.24.16.24
172.24.14.27
172.24.14.26
172.24.18.16
172.24.20.25
172.24.20.31
172.24.18.30
172.24.18.29
--


excellent! that worked

cheers
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question