Ping Average MS


What is the best way to output test-connection and report the average ms time to html?
Alex YoungAsked:
Who is Participating?
SubsunConnect With a Mentor Commented:
(Test-Connection $IP.RouterIP | Measure ResponseTime -Average).Average


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

Open in new window

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.
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>"



	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

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.