OTNAdmin
asked on
Powershell Ping script
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:
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) }
ASKER
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?
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) }
-exclude
ASKER
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks that worked
maybe this link can help you:
http://www.pluralsight-training.net/community/blogs/keith/archive/2007/01/22/45814.aspx
Kind regards,
JP