Modules.PSOneTools icon indicating copy to clipboard operation
Modules.PSOneTools copied to clipboard

Test-PSOnePing: System.Net.Networkinformation.Ping details

Open scriptingstudio opened this issue 6 years ago • 1 comments

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}
}

scriptingstudio avatar Nov 21 '19 10:11 scriptingstudio

Great suggestion! Will look at it and incorporate the change.

TobiasPSP avatar Nov 21 '19 13:11 TobiasPSP