Monday, March 19, 2012

Get an Average Ping Response time of multiple Servers using PowerShell.


Hi,

If you are an IT admin, then I am sure you are using PING command everyday. In PowerShell we have an Test-Connection command which is a very good alternative of it. as we know PowerShell is an object based scripting language by using it we can do much more.

Whenever I/we have network or internet related issues we do "Ping google.com" to check the response time of website and then we can know how our internet is performing. Sometime rather then pinging one  website we do ping few more website.

So i was thinking that if i can ping multiple servers in one time and get there average as as result. I don't want an fancy script just a simple script which i can run from my PowerShell console and view the result there.

So i just create a simple PowerShell script which can do this for us.

You can download the script from here : http://gallery.technet.microsoft.com/scriptcenter/Get-the-Average-Ping-49fc4924

#######################################
$CompName = "dc-Local","google.com","rediff.com","yahoo.com"
foreach ($comp in $CompName) {
       $test = (Test-Connection -ComputerName $comp -Count 4  | measure-Object -Property ResponseTime -Average).average
       $response = ($test -as [int] )
       write-Host "The Average response time for" -ForegroundColor Green -NoNewline;write-Host " `"$comp`" is " -ForegroundColor Red -NoNewline;;Write-Host "$response ms" -ForegroundColor Black -BackgroundColor white
}
##########################################
19-03-2012 14-05-36 


Thanks
Aman Dhally

1 comment:

  1. Thanks for sharing this script, just made one of my tasks today super easy. Modified the script to output to a csv as well as the console.

    $CompName = "dc-Local","google.com","rediff.com","yahoo.com"

    Write-Output "ComputerName,ResponseTime (ms)" > C:\Get-PingAvg.csv

    foreach ($comp in $CompName) {

    $test = (Test-Connection -ComputerName $comp -Count 4 | measure-Object -Property ResponseTime -Average).average
    $response = ($test -as [int] )
    write-Host "The Average response time for" -ForegroundColor Green -NoNewline;write-Host " `"$comp`" is " -ForegroundColor Red -NoNewline;;Write-Host "$response ms" -ForegroundColor Black -BackgroundColor white
    Write-Output "$comp,$response" >> C:\Get-PingAvg.csv

    Cheers!

    ReplyDelete

Note: Only a member of this blog may post a comment.