[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 19748
  • Last Modified:

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

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
tobe1424
Asked:
tobe1424
  • 7
  • 5
2 Solutions
 
SubsunCommented:
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
 
tobe1424Author Commented:
Thanks much! Let me give that a shot
0
 
SubsunCommented:
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
Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

 
tobe1424Author Commented:
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
 
SubsunCommented:
You can remove the  parameter -Count 2 and try..
0
 
tobe1424Author Commented:
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
 
tobe1424Author Commented:
let me try
0
 
tobe1424Author Commented:
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
 
SubsunCommented:
What is the result for
Test-Connection 172.24.20.36 

Open in new window

0
 
tobe1424Author Commented:
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
 
SubsunCommented:
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
 
tobe1424Author Commented:
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

Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

  • 7
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now