2021-04-21 19:53:52 +02:00
|
|
|
|
<#
|
2021-07-13 21:10:02 +02:00
|
|
|
|
.SYNOPSIS
|
|
|
|
|
check-ping.ps1
|
|
|
|
|
.DESCRIPTION
|
2021-08-29 17:50:03 +02:00
|
|
|
|
Checks the ping latency from the local computer to the internet.
|
2021-07-13 21:10:02 +02:00
|
|
|
|
.EXAMPLE
|
|
|
|
|
PS> .\check-ping.ps1
|
|
|
|
|
.LINK
|
|
|
|
|
https://github.com/fleschutz/PowerShell
|
|
|
|
|
.NOTES
|
2021-08-29 17:50:03 +02:00
|
|
|
|
Author: Markus Fleschutz · License: CC0
|
2021-03-30 09:06:30 +02:00
|
|
|
|
#>
|
|
|
|
|
|
|
|
|
|
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 {
|
2021-05-02 21:30:48 +02:00
|
|
|
|
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
2021-03-30 09:06:30 +02:00
|
|
|
|
exit 1
|
|
|
|
|
}
|