Ping Average MS

Hi,

What is the best way to output test-connection and report the average ms time to html?
LVL 1
Alex YoungAsked:
Who is Participating?
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.

Prashant GirennavarCommented:
Can you please let us know the exact requirement here?

Do you want this test-connection output for multiple computers?

what the output should contain only the MS time in html? or Server name and their MS time in html?

-Prashant Girennavar.
0
Alex YoungAuthor Commented:
Yeah so basically here is my code i want another column to just show the average ms time if that makes sense.

$Date = Get-Date -Format "dddd dd MMMM yyyy"
$Time = Get-Date -Format "hh:mm:ss"

$IndexPage = "C:\Remote\Index.html" # This Creates The Index Page
New-Item -ItemType file $IndexPage -Force # Creates The Page

Add-Content $IndexPage "<HTML>"
Add-Content $IndexPage "<HEAD>"
Add-Content $IndexPage "<META HTTP-EQUIV='refresh' CONTENT='5'>"
Add-Content $IndexPage '<link rel="stylesheet" type="text/css" href="C:\Remote\Router.css">'
Add-Content $IndexPage "</HEAD>"
Add-Content $IndexPage '<table id="main" width="auto" align="center" border="1" border-collapse="collapse">'
Add-Content $IndexPage "<tr bgcolor='#D0E6FF'>"
Add-Content $IndexPage "<td colspan='4' height='25' align='center'>"
Add-Content $IndexPage "<font face='tahoma' color='#000000' size='2'><b>Router Checker</b></font><BR>"
Add-Content $IndexPage "<font face='Arial' color='#000000' size='2'><b>Date: $Date</b><BR>"
Add-Content $IndexPage "<font face='Arial' color='#00000' size='2'><b>Time: $Time</b>"
Add-Content $IndexPage "</td>"
Add-Content $IndexPage "</tr>"
Add-Content $IndexPage "</table><BR>"

Add-Content $IndexPage '<table id="main" class="sortable" <width="auto" align="center" border="1">'
Add-Content $IndexPage "<tr bgcolor='#D0E6FF'>"
Add-Content $IndexPage "<th width='auto' align='center'>Client</th>"
Add-Content $IndexPage "<th width='auto' align='center'>IP Address</th>"
Add-Content $IndexPage "<th width='auto' align='center'>Up</th>"
Add-Content $IndexPage "<th width='auto' align='center'>Down</td></th>"

$ipcsv = Import-Csv C:\Remote\ip.csv -Header Client,RouterIP


foreach ($IP in $ipcsv)

{
	
	$Hostname = $_.Client
	$IPRouter = $_.RouterIP
	
	$Client = $IP.Client
	$IPAddresses = $IP.RouterIP
	
$result = New-Object psObject -Property @{'Client'=$Hostname;'RouterIP'=$IPRouter}
	
Write-Host "Trying $($IP)" -ForegroundColor White

	Try {
 
	$IPComputer = Test-Connection $IP.RouterIP -Count 2 -ErrorAction Stop | Select -ExpandProperty ipv4Address -ea STOP | `
	Select -ExpandProperty ipAddressToString

	Write-Host "Success" -ForegroundColor Green

	Add-Content $IndexPage "<tr><td>$Client</td><td>$IPAddresses</td><td><font size'3' color='green'>Sucess</font></td><td></td></tr>"

	}

	catch

	{
	Write-Host "Down" -ForegroundColor Red

	Add-Content $IndexPage "<tr><td>$Client</td><td>$IPAddresses</td><td></td><td><font size'3' color='red'>Failed</font></td></tr>"
	}

}
Add-Content $IndexPage "</tr></table>"

Open in new window

0
SubsunCommented:
Try..
(Test-Connection $IP.RouterIP | Measure ResponseTime -Average).Average

or

(Test-Connection $IP.RouterIP -Count 2 | Measure ResponseTime -Average).Average

Open in new window

0

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
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
Powershell

From novice to tech pro — start learning today.