Home > Uncategorized > Powershell: Very fast ping

Powershell: Very fast ping

Citing a post, I’ve thrown together a powershell function that is a very fast ping.

It is a useful replacement for the test-connection cmdlet, who’s timeout is more than desirably long.

Advertisements
  1. Kyle7286
    March 13, 2015 at 3:34 pm

    I have to ping over 700 servers and for the one’s that are online, detect if an application is running. This so far was the fastest way for me to perform that task, taking about 2 minutes to complete all servers.

    • March 13, 2015 at 4:20 pm

      Happy to help! I think a condition to speed up failed DNS resolution can make it even faster.

      • Kyle7286
        March 13, 2015 at 6:40 pm

        Thanks for the suggestion.
        It got me thinking and now I developed this which gets me the results I want in half the time, now 45 seconds or less instead of 2-3 minutes. I will of course modify it into a table for me to push commands to the server that is online.

        #Get-Content "Path\do\your\serverlist\file.txt"
        #If Server doesn't exist in dns, skip
        #If Server is pinged 0% loss, it's online
        #If Server is pinged 100% loss, it's offline
        
        Get-Content $ServerList | ForEach-Object {
            $NSResult = [string](NSlookup $_)
          
            If ($NSResult.contains("Name:    "+[string]$_) ) 
            {
                $PingResult =[String](ping -w 100 -n 1 -a $_)   
                If     ($PingResult.Contains("100% loss") )   { Write-Host $_ = Offline }
                ElseIf ($PingResult.Contains("0% loss")   )   { Write-Host $_ = Online  }
                Else {Write-Host $_ Something went wrong}
            }
        }
        
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: