Updated ping-host.ps1

This commit is contained in:
Markus Fleschutz 2025-02-23 11:12:27 +01:00
parent 0a56175e54
commit fc487f5f3d

View File

@ -7,7 +7,7 @@
Specifies the hostname or IP address to ping (x.com by default) Specifies the hostname or IP address to ping (x.com by default)
.EXAMPLE .EXAMPLE
PS> ./ping-host.ps1 x.com PS> ./ping-host.ps1 x.com
'x.com' is up 👍 (20ms to IP 104.244.42.1) 'x.com' is up and running 👍 (20ms to IP 104.244.42.1)
.LINK .LINK
https://github.com/fleschutz/PowerShell https://github.com/fleschutz/PowerShell
.NOTES .NOTES
@ -22,7 +22,7 @@ try {
[Threading.Tasks.Task]::WaitAll($tasks) [Threading.Tasks.Task]::WaitAll($tasks)
foreach($ping in $tasks.Result) { foreach($ping in $tasks.Result) {
if ($ping.Status -eq "Success") { if ($ping.Status -eq "Success") {
Write-Output "✅ '$hostname' is up 👍 ($($ping.RoundtripTime / 2)ms to IP $($ping.Address))" Write-Output "✅ '$hostname' is up and running 👍 ($($ping.RoundtripTime / 2)ms to IP $($ping.Address))"
exit 0 # success exit 0 # success
} else { } else {
Write-Output "⚠️ No reply from '$hostname' (IP $($ping.Address)) - check the connection or maybe the host is down." Write-Output "⚠️ No reply from '$hostname' (IP $($ping.Address)) - check the connection or maybe the host is down."
@ -34,4 +34,4 @@ try {
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }