mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-04-08 17:28:18 +02:00
Update check-ping.ps1
This commit is contained in:
parent
6414af73c1
commit
328decd842
@ -2,7 +2,7 @@
|
|||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Checks the ping latency
|
Checks the ping latency
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
This PowerShell script checks the ping latency from the local computer to the given hosts.
|
This PowerShell script checks the ping latency from the local computer to 9 popular hosts.
|
||||||
.PARAMETER hosts
|
.PARAMETER hosts
|
||||||
Specifies the hosts to check, seperated by commata (default is: amazon.com,bing.com,cnn.com,dropbox.com,facebook.com,google.com,live.com,twitter.com,youtube.com)
|
Specifies the hosts to check, seperated by commata (default is: amazon.com,bing.com,cnn.com,dropbox.com,facebook.com,google.com,live.com,twitter.com,youtube.com)
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
@ -17,11 +17,10 @@
|
|||||||
param([string]$hosts = "amazon.com,bing.com,cnn.com,dropbox.com,facebook.com,google.com,live.com,twitter.com,youtube.com")
|
param([string]$hosts = "amazon.com,bing.com,cnn.com,dropbox.com,facebook.com,google.com,live.com,twitter.com,youtube.com")
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Write-Progress "⏳ Pinging hosts in parallel..."
|
Write-Progress "⏳ Sending a ping to 9 popular hosts..."
|
||||||
$HostsArray = $hosts.Split(",")
|
$HostsArray = $hosts.Split(",")
|
||||||
$Pings = Test-Connection -computerName $HostsArray -count 1
|
$Pings = Test-Connection -computerName $HostsArray -count 1
|
||||||
|
|
||||||
Write-Progress "⏳ Calculating results..."
|
|
||||||
[int]$Min = 9999999
|
[int]$Min = 9999999
|
||||||
[int]$Max = [int]$Avg = 0
|
[int]$Max = [int]$Avg = 0
|
||||||
foreach($Ping in $Pings) {
|
foreach($Ping in $Pings) {
|
||||||
@ -32,8 +31,8 @@ try {
|
|||||||
}
|
}
|
||||||
$Avg /= $Pings.count
|
$Avg /= $Pings.count
|
||||||
|
|
||||||
|
Write-Progress -Completed "."
|
||||||
Write-Host "✅ Ping latency is $($Min)ms...$($Max)ms, $($Avg)ms average"
|
Write-Host "✅ Ping latency is $($Min)ms...$($Max)ms, $($Avg)ms average"
|
||||||
Write-Progress -Completed "Ping finished."
|
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
} catch {
|
} catch {
|
||||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||||
|
Loading…
Reference in New Issue
Block a user