get-connection: show ping result and determine average ping response


I'm using the following line to get the results from pinging a machine
test-Connection -ComputerName $Server$domain -Count $pingsToSend | select Address, ResponseTime | Out-File $outfile -Append

What I would like to do is also get the average ping time.  

I realize there I can pipe to  measure-Object -Property ResponseTime -Average).average to get the average time, but I can't figure out a way to get both individual response time and then get the average

For example I want to see something like this written to $outfile if $pingsToSend =3 (in real life, this value will be set to about 100

Address                                                                                                    ResponseTime
-------                                                                                                    ------------
machine1                                                                                              19
machine1                                                                                              29
machine1                                                                                              22

Average  ping time for machine1 is                                                  23.3

Thanks for your help
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

When you need to use data for more than one purpose (like writing to a file, and performing a calculation), you should save the data to a variable so it can be reused.
$temp = Test-Connection -ComputerName $Server$domain -Count $pingsToSend | select Address, ResponseTime
$temp | Out-File $outfile -Append
$avg = ($temp | Measure-Object -Property ResponseTime -Average).average 
Write-Output "Average ping time for $Server$domain is:  $avg" | Out-File $outfile -Append

Open in new window

In this case you could also use Tee-Object, but the above is more straight-forward.
$avg = (Test-Connection -ComputerName $Server$domain -Count $pingsToSend | select Address, ResponseTime |
 Tee-Object -FilePath $outfile -Append | Measure-Object -Property ResponseTime -Average).average
Write-Output "Average ping time for $Server$domain is:  $avg" | Out-File $outfile -Append

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mcalo1Author Commented:
Awesome!  Thanks for the info.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.