I'm trying to create a script that will list the servers I need to list along with the latency returned from each server, I need the list to be in ascending or descending order based on ping.
What I've come up with so far has given basically what I want, but if the ping returned is above 100 on one server, the other values are considered to be higher if they start with a value higher than 1.
I understand that I need the ping value returned as an integer, but I haven't been able to figure out exactly how to accomplish that with out removing the server name.
Anyway, here's what I've come up with so far
function TestNetwork {
$global:array = @("<ServerName>:<ipaddress>"; "<ServerName>:<ipaddress>"; "<ServerName>:<ipaddress>")
foreach ($str in $global:array) {
$avg = 0
$server = $($str -split ":")[0]
$PingServer = Test-Connection -Count 3 $server
$avg = ($PingServer | Measure-Object ResponseTime -Average)
$calc = [System.Math]::Round($avg.Average)
$output = "{000} | " -f $($calc) + $server
$Output
}
}
TestNetwork | Sort numerical -Descending `
and here are the results I get
75 | Server 73 | Server 110 | Server