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