mirror of
https://github.com/fleschutz/PowerShell.git
synced 2024-11-27 02:14:31 +01:00
Improved ping-host.ps1 and write-headline.ps1
This commit is contained in:
parent
702506f9a1
commit
305077d5cd
@ -1,6 +1,6 @@
|
|||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Ping a host continuously
|
Ping a host
|
||||||
.DESCRIPTION
|
.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 continously and shows the roundtrip times in a horizontal chart.
|
||||||
.PARAMETER hostname
|
.PARAMETER hostname
|
||||||
@ -9,11 +9,12 @@
|
|||||||
Specifies the time interval in milliseconds to repeat the ping (1000 by default)
|
Specifies the time interval in milliseconds to repeat the ping (1000 by default)
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS> ./ping-host.ps1
|
PS> ./ping-host.ps1
|
||||||
|
-----------------------------------------
|
||||||
Ping Roundtrip Times to Host: windows.com
|
Ping Roundtrip Times to windows.com
|
||||||
██████████████ 136ms
|
-----------------------------------------
|
||||||
████████████████ 154ms
|
#1 ██████████████ 136ms
|
||||||
█████████████████████████ 234ms
|
#2 ████████████████ 154ms
|
||||||
|
#3 █████████████████████████ 234ms
|
||||||
...
|
...
|
||||||
.LINK
|
.LINK
|
||||||
https://github.com/fleschutz/PowerShell
|
https://github.com/fleschutz/PowerShell
|
||||||
@ -36,7 +37,7 @@ function GetPingLatency([string]$hostname) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function WriteChartLine { param([float]$value, [float]$maxValue, [string]$text)
|
function WriteChartLine { param([float]$value, [float]$maxValue, [string]$text)
|
||||||
$num = ($value * 110.0) / $maxValue
|
$num = ($value * 108.0) / $maxValue
|
||||||
while ($num -ge 1.0) {
|
while ($num -ge 1.0) {
|
||||||
Write-Host -noNewLine "█"
|
Write-Host -noNewLine "█"
|
||||||
$num -= 1.0
|
$num -= 1.0
|
||||||
@ -60,11 +61,14 @@ function WriteChartLine { param([float]$value, [float]$maxValue, [string]$text)
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Write-Host "`nPing Roundtrip Times to Host: $($hostname)" -foregroundColor green
|
& "$PSScriptRoot/write-headline.ps1" "Ping Roundtrip Times to $($hostname)"
|
||||||
|
[int]$count = 1
|
||||||
do {
|
do {
|
||||||
[float]$latency = GetPingLatency $hostname
|
[float]$latency = GetPingLatency $hostname
|
||||||
|
Write-Host "#$count " -noNewline
|
||||||
WriteChartLine $latency 1000.0 "$($latency)ms"
|
WriteChartLine $latency 1000.0 "$($latency)ms"
|
||||||
Start-Sleep -Milliseconds $timeInterval
|
Start-Sleep -Milliseconds $timeInterval
|
||||||
|
$count++
|
||||||
} while($true)
|
} while($true)
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
} catch {
|
} catch {
|
||||||
|
@ -7,9 +7,9 @@
|
|||||||
Specifies the text to write
|
Specifies the text to write
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS> ./write-headline.ps1 "Hello World"
|
PS> ./write-headline.ps1 "Hello World"
|
||||||
|
-----------------
|
||||||
* Hello World *
|
Hello World
|
||||||
---------------
|
-----------------
|
||||||
.LINK
|
.LINK
|
||||||
https://github.com/fleschutz/PowerShell
|
https://github.com/fleschutz/PowerShell
|
||||||
.NOTES
|
.NOTES
|
||||||
@ -21,11 +21,10 @@ param([string]$text = "")
|
|||||||
try {
|
try {
|
||||||
if ($text -eq "") { $text = Read-Host "Enter the text to write" }
|
if ($text -eq "") { $text = Read-Host "Enter the text to write" }
|
||||||
|
|
||||||
Write-Host "`n* $text *" -foregroundColor green
|
|
||||||
[int]$len = $text.Length
|
[int]$len = $text.Length
|
||||||
[string]$line = "----"
|
[string]$line = "------"
|
||||||
for ([int]$i = 0; $i -lt $len; $i++) { $line += "-" }
|
for ([int]$i = 0; $i -lt $len; $i++) { $line += "-" }
|
||||||
Write-Host "$line" -foregroundColor green
|
Write-Host "`n$line`n $text`n$line" -foregroundColor green
|
||||||
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