as we know, test-connection has a three second delay if the PC isn't found
So in comes [Net.NetworkInformation.Ping]::New().SendPingAsync()
I have found it likes to give me false statements, such as, a PC in California, will ping fine, then the next time it doesn't. It will say it cannot find it. Run it again, finds it. I thought it was because I was on VPN this weekend, but now I'm wired still having the same issues.
This is my script, super easy
- foreach ($D in $DNS)
- {
- $ping = [Net.NetworkInformation.Ping]::New().SendPingAsync("$server.$D",250) | Where-Object {$_.Result.Status -eq 'Success'}
- if($ping){
- "$server.$suffix".toupper();
- break
- }
- else{
- }
- }