I have a Ping function that I am using to ping machines with in a bigger script. One thing that I noticed is that sometime I get a failure and it reports the machine as "timed out"
I would like to run another ping within this function to try it again to ensure that the machine is actually timing out. Is there a way to put an If else statement in a Try block?
Here is the function
function Ping([string]$hostname, [int]$timeout = 200) {
$ping = new-object System.Net.NetworkInformation.Ping #creates a ping object
try { $result = $ping.send($hostname, $timeout).Status.ToString() }
catch { $result = "Failure" }
return $result
}