[Net.NetworkInformation.Ping]::New().SendPingAsync() - too fast?

Ask your Windows PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Post Reply
User avatar
localpct
Posts: 301
Joined: Wed Sep 09, 2015 12:53 pm

[Net.NetworkInformation.Ping]::New().SendPingAsync() - too fast?

Post by localpct » Mon Nov 11, 2019 9:55 am

So I was doing some testing on how to get the fastest, ping return on machines
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
  1. foreach ($D in $DNS)
  2.  
  3. {
  4.  
  5.     $ping = [Net.NetworkInformation.Ping]::New().SendPingAsync("$server.$D",250) | Where-Object {$_.Result.Status -eq 'Success'}
  6.  
  7.     if($ping){
  8.  
  9.     "$server.$suffix".toupper();
  10.  
  11.   break
  12.  
  13. }
  14.  
  15. else{
  16.  
  17. }
  18.  
  19. }

jvierra
Posts: 14009
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: [Net.NetworkInformation.Ping]::New().SendPingAsync() - too fast?

Post by jvierra » Mon Nov 11, 2019 10:01 am

This is not a scripting issue. It sounds like your DNS servers have issues.

User avatar
localpct
Posts: 301
Joined: Wed Sep 09, 2015 12:53 pm

Re: [Net.NetworkInformation.Ping]::New().SendPingAsync() - too fast?

Post by localpct » Mon Nov 11, 2019 10:33 am

that is an answer I can live with. I also had this issue with Asynchronous Network Ping
https://gallery.technet.microsoft.com/s ... g-abdf01aa

Post Reply