I have been working on a script that will take a CSV of IP addresses and ping them. However, I’m hitting a road-block.
I would like to ping the IP address and have two outcomes:
1.) If ping is successful, do nothing.
2.) If ping is unsuccessful, add that IP address to a separate CSV which will be exported at the end of the script.
This would loop until we run out of IPs to ping on the list.
So far what I have below works for creating a loop and pinging the IPs from a CSV, but I’m unsure how to add in the two actions above.
Please don’t spell it out; give me a tip and let me run with it. This project has been fun and I feel like I’m so close to the answer!
$path = "C:\Temp\TestFolder\FolderName.csv"
$csv = Import-Csv -Path $path
foreach($line in $csv)
{
$properties = $line | Get-Member -MemberType Properties
for($i=0; $i -lt $properties.Count;$i++)
{
$column = $properties[$i]
$columnvalue = $line | Select -ExpandProperty $column.Name
#Write-Output $columnvalue #This line is unneeded. It simply tells the viewer which IP address we're on.
$testconnection = Test-Connection -ComputerName $columnvalue
$testconnection
}
}