Updated the manuals

This commit is contained in:
Markus Fleschutz
2024-11-08 12:35:11 +01:00
parent 53eb60baa3
commit 54635c32da
636 changed files with 5289 additions and 2027 deletions

View File

@ -1,15 +1,15 @@
Script: *ping-host.ps1*
========================
This PowerShell script pings the given host continously and shows the roundtrip times in a horizontal chart.
This PowerShell script pings the given host.
Parameters
----------
```powershell
PS> ./ping-host.ps1 [[-hostname] <String>] [[-timeInterval] <Int32>] [<CommonParameters>]
/home/markus/Repos/PowerShell/scripts/ping-host.ps1 [[-hostname] <String>] [<CommonParameters>]
-hostname <String>
Specifies the hostname or IP address of the host to ping (windows.com by default)
Specifies the hostname or IP address to ping (windows.com by default)
Required? false
Position? 1
@ -17,15 +17,6 @@ PS> ./ping-host.ps1 [[-hostname] <String>] [[-timeInterval] <Int32>] [<CommonPar
Accept pipeline input? false
Accept wildcard characters? false
-timeInterval <Int32>
Specifies the time interval in milliseconds to repeat the ping (1000 by default)
Required? false
Position? 2
Default value 1000
Accept pipeline input? false
Accept wildcard characters? false
[<CommonParameters>]
This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction,
WarningVariable, OutBuffer, PipelineVariable, and OutVariable.
@ -34,15 +25,8 @@ PS> ./ping-host.ps1 [[-hostname] <String>] [[-timeInterval] <Int32>] [<CommonPar
Example
-------
```powershell
PS> ./ping-host.ps1
Ping Roundtrip Times to Host: windows.com
██████████████ 136ms
████████████████ 154ms
█████████████████████████ 234ms
...
PS> ./ping-host.ps1 x.com
x.com is up and running (11ms latency).
```
@ -59,72 +43,37 @@ Script Content
```powershell
<#
.SYNOPSIS
Ping a host continuously
Pings a host
.DESCRIPTION
This PowerShell script pings the given host continously and shows the roundtrip times in a horizontal chart.
This PowerShell script pings the given host.
.PARAMETER hostname
Specifies the hostname or IP address of the host to ping (windows.com by default)
.PARAMETER timeInterval
Specifies the time interval in milliseconds to repeat the ping (1000 by default)
Specifies the hostname or IP address to ping (windows.com by default)
.EXAMPLE
PS> ./ping-host.ps1
Ping Roundtrip Times to Host: windows.com
██████████████ 136ms
████████████████ 154ms
█████████████████████████ 234ms
...
PS> ./ping-host.ps1 x.com
✅ x.com is up and running (11ms latency).
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
param([string]$hostname = "windows.com", [int]$timeInterval = 1000)
param([string]$hostname = "windows.com")
function GetPingLatency([string]$hostname) {
$hostsArray = $hostname.Split(",")
$tasks = $hostsArray | foreach {
(New-Object Net.NetworkInformation.Ping).SendPingAsync($_,1000)
}
$tasks = $hostsArray | foreach { (New-Object Net.NetworkInformation.Ping).SendPingAsync($_,1500) }
[Threading.Tasks.Task]::WaitAll($tasks)
foreach($ping in $tasks.Result) {
if ($ping.Status -eq "Success") { return $ping.RoundtripTime }
}
return 1000
}
function WriteChartLine { param([float]$value, [float]$maxValue, [string]$text)
$num = ($value * 110.0) / $maxValue
while ($num -ge 1.0) {
Write-Host -noNewLine "█"
$num -= 1.0
}
if ($num -ge 0.875) {
Write-Host -noNewLine "▉"
} elseif ($num -ge 0.75) {
Write-Host -noNewLine "▊"
} elseif ($num -ge 0.625) {
Write-Host -noNewLine "▋"
} elseif ($num -ge 0.5) {
Write-Host -noNewLine "▌"
} elseif ($num -ge 0.375) {
Write-Host -noNewLine "▍"
} elseif ($num -ge 0.25) {
Write-Host -noNewLine "▎"
} elseif ($num -ge 0.125) {
Write-Host -noNewLine "▏"
}
Write-Host " $text"
foreach($ping in $tasks.Result) { if ($ping.Status -eq "Success") { return $ping.RoundtripTime } }
return 1500
}
try {
Write-Host "`nPing Roundtrip Times to Host: $($hostname)" -foregroundColor green
do {
[float]$latency = GetPingLatency $hostname
WriteChartLine $latency 1000.0 "$($latency)ms"
Start-Sleep -Milliseconds $timeInterval
} while($true)
[int]$latency = GetPingLatency($hostname)
if ($latency -eq 1500) {
Write-Host "⚠️ Host '$hostname' doesn't respond - check the connection or maybe the host is down."
exit 1
}
Write-Host "✅ $hostname is up and running ($($latency)ms latency)."
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
@ -132,4 +81,4 @@ try {
}
```
*(generated by convert-ps2md.ps1 using the comment-based help of ping-host.ps1 as of 08/15/2024 09:50:52)*
*(generated by convert-ps2md.ps1 using the comment-based help of ping-host.ps1 as of 11/08/2024 12:34:53)*