Skip to content

Commit f60c8e0

Browse files
committed
Update check-ping.ps1
1 parent fa3865a commit f60c8e0

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

Scripts/check-ping.ps1

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
Specifies the hosts to check, seperated by commata (default is: amazon.com,bing.com,cnn.com,dropbox.com,facebook.com,github.com,google.com,live.com,twitter.com,youtube.com)
88
.EXAMPLE
99
PS> ./check-ping
10-
✅ Ping latency is 13ms...109ms with 25ms average
10+
✅ Ping latency is 13ms...109ms with 29ms average (0 loss)
1111
.LINK
1212
https://github.com/fleschutz/PowerShell
1313
.NOTES
@@ -25,18 +25,20 @@ try {
2525
}
2626
[Threading.Tasks.Task]::WaitAll($t)
2727
[int]$Min = 9999999
28-
[int]$Max = [int]$Avg = [int]$Count = 0
28+
[int]$Max = [int]$Avg = [int]$SuccessCount = [int]$LossCount = 0
2929
foreach($ping in $t.Result) {
3030
if ($ping.Status -eq "Success") {
3131
[int]$Latency = $ping.RoundtripTime
3232
if ($Latency -lt $Min) { $Min = $Latency }
3333
if ($Latency -gt $Max) { $Max = $Latency }
3434
$Avg += $Latency
35-
$Count++
35+
$SuccessCount++
36+
} else {
37+
$LossCount++
3638
}
3739
}
38-
$Avg /= $Count
39-
Write-Host " $($Min)ms...$($Max)ms with $($Avg)ms average"
40+
$Avg /= $SuccessCount
41+
Write-Host " $($Min)ms...$($Max)ms with $($Avg)ms average ($LossCount loss)"
4042
exit 0 # success
4143
} catch {
4244
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"

0 commit comments

Comments
 (0)