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
#######################################
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
}
##########################################
You can download the script from here : http://gallery.technet.microsoft.com/scriptcenter/Get-the-Average-Ping-49fc4924
Thanks
Aman Dhally
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.
ReplyDelete$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!