Solved

Powershell Ping script

Posted on 2010-09-22
6
1,647 Views
Last Modified: 2012-05-10
I want to create a powershell script that will ping a range of IP's then out put the results. Here is the challenge, I want to know if it is possible to only have the output file contain the IP address of the servers that are reachable.

Below is the script I am working with, right now it does not output any results:


function ping-ip

{ param($ip)

$ping = New-Object System.Net.NetworkInformation.Ping #new ping 

$Reply = $ping.send($ip)          #send ping   

if ($Reply.Status -eq "Success")        #ping status

{  Write-Host "IP reachable: " $ip -ForeGroundColor "Green" #succeeded

} 

else 

{

Write-Host "IP not reachable: " $ip -ForeGroundColor "Red" #not reacheble 

}

}

0..255 | foreach { $ip = "10.224.129.$_" ; (ping-ip $ip) }

Open in new window

0
Comment
Question by:OTNAdmin
  • 3
  • 2
6 Comments
 
LVL 4

Expert Comment

by:JP64
ID: 33734210
0
 

Author Comment

by:OTNAdmin
ID: 33734768
I was able to get it working by just modifying the script see below, I got it to output to a txt file by changing it to write-output.

Now I have one last component I need help with. when I am pinging the subnet is there a way to omit a certain ip address from the loop?
function ping-ip

{ param($ip)

$ping = New-Object System.Net.NetworkInformation.Ping #new ping 

$Reply = $ping.send($ip)          		#send ping   

if ($Reply.Status -eq "Success")        #ping status

{  Write-Output $ip # -ForeGroundColor "Green" #succeeded

} 

else 

{

#Write-Host "IP not reachable: " $ip -ForeGroundColor "Red" #not reacheble 

}

}

0..255 | foreach { $ip = "10.224.129.$_" ; (ping-ip $ip) }

Open in new window

0
 
LVL 7

Expert Comment

by:wittyslogan
ID: 33734802
-exclude
0
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 

Author Comment

by:OTNAdmin
ID: 33735478
I am new to powershell can you assist in how I can add it to the following script? The IP i want to exclude is 10.224.129.103
0
 
LVL 7

Accepted Solution

by:
wittyslogan earned 500 total points
ID: 33743170
Hello,
I am also new and on reflection you could do the following
0..102+104..255 | foreach { $ip = "10.224.129.$_" ; (ping-ip $ip }

basically this looks through 2 ranges 0-102 and then 104-256.  I think you can do this with as many ranges as you want.

0
 

Author Closing Comment

by:OTNAdmin
ID: 33743684
thanks that worked
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Are you one of those front-line IT Service Desk staff fielding calls, replying to emails, all-the-while working to resolve end-user technological nightmares? I am! That's why I have put together this brief overview of tools and techniques I use in o…
This script checks a path to see if a folder exists. If the folder does exist you will get output "The folder has previously been created. No action taken" If not it will create the folder. Then adds one user modify permission to the folder. It …
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
The viewer will learn how to dynamically set the form action using jQuery.

914 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now