Modules.PSOneTools
Modules.PSOneTools copied to clipboard
Test-PSOnePing: System.Net.Networkinformation.Ping details
Method .send() takes time to resolve hostname if you pass not ipaddress. So if you pass a dead name you will get an exception. I would suggest this solution:
if (-not [bool]($ComputerName -as [ipaddress])) {
try {
$result = [System.Net.Dns]::BeginGetHostByName($ComputerName, $null, $null)
$result = if ($result.AsyncWaitHandle.WaitOne($timeout)) { [System.Net.Dns]::EndGetHostByName($result) }
if (-not $result) {return $false}
$ComputerName = $result.AddressList.IPAddressToString
} catch {return $false}
}
Great suggestion! Will look at it and incorporate the change.