PowerShell/Scripts/check-ping.ps1

33 lines
907 B
PowerShell
Raw Normal View History

2021-04-21 19:53:52 +02:00
<#
2021-04-07 15:17:49 +02:00
.SYNTAX check-ping.ps1
2021-03-30 09:06:30 +02:00
.DESCRIPTION checks the ping latency to the internet
.LINK https://github.com/fleschutz/PowerShell
.NOTES Author: Markus Fleschutz / License: CC0
#>
try {
write-verbose "Sending pings to the internet ..."
$Pings = test-connection -count 1 -computerName heise.de,cnn.com,github.com,www.microsoft.com,dropbox.com,amazon.com,google.com,bing.com,youtube.com
[int]$Min = 9999999
[int]$Max = 0
[int]$Avg = 0
foreach($Ping in $Pings) {
2021-03-30 09:43:58 +02:00
if ($IsLinux) {
[int]$Latency = $Ping.latency
} else {
2021-03-30 09:47:21 +02:00
[int]$Latency = $Ping.ResponseTime
2021-03-30 09:43:58 +02:00
}
if ($Latency -lt $Min) { $Min = $Latency }
if ($Latency -gt $Max) { $Max = $Latency }
$Avg += $Latency
2021-03-30 09:06:30 +02:00
}
$Avg = $Avg / $Pings.count
2021-04-17 18:54:45 +02:00
"✔️ $Avg ms average ping latency ($Min ms min, $Max ms max)"
2021-03-30 09:06:30 +02:00
exit 0
} catch {
write-error "ERROR: line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}