This may still throw an exception, but it will be caught in the catch block where it will write the type of the exception to the console:
$ErrorActionPreference = "Stop"
$ping = New-Object System.Net.NetworkInformation.Ping
try
{
$pingReply = $ping.Send("computername")
}
catch [System.Net.NetworkInformation.PingException]
{
$_.Exception.InnerException.GetType().ToString()
}
switch ($pingReply.Status)
{
Success { }
DestinationNetworkUnreachable { }
DestinationHostUnreachable { }
DestinationProtocolUnreachable { }
DestinationPortUnreachable { }
DestinationProhibited { }
NoResources { }
BadOption { }
HardwareError { }
PacketTooBig { }
TimedOut { }
BadRoute { }
TtlExpired { }
TtlReassemblyTimeExceeded { }
ParameterProblem { }
SourceQuench { }
BadDestination { }
DestinationUnreachable { }
TimeExceeded { }
BadHeader { }
UnrecognizedNextHeader { }
IcmpError { }
DestinationScopeMismatch { }
Unknown { }
default { }
}
Details of the enumeration values can be found here: http://msdn.microsoft.com/en-us/lib...tatus.aspx