Updated check-uptime.ps1

This commit is contained in:
Markus Fleschutz 2024-09-27 17:38:59 +02:00
parent a8bafada38
commit 7229b3d980

View File

@ -44,11 +44,11 @@ try {
$uptime = New-TimeSpan -Start $lastBootTime -End (Get-Date) $uptime = New-TimeSpan -Start $lastBootTime -End (Get-Date)
} }
$status = "" $status = ""
$pending = "No pending reboot" $pending = ""
if ($IsLinux) { if ($IsLinux) {
if (Test-Path "/var/run/reboot-required") { if (Test-Path "/var/run/reboot-required") {
$status = "⚠️ " $status = "⚠️ "
$pending = "Pending reboot (found: /var/run/reboot-required)" $pending = "with pending reboot (found /var/run/reboot-required)"
} }
} else { } else {
$reason = "" $reason = ""
@ -84,10 +84,10 @@ try {
} }
if ($reason -ne "") { if ($reason -ne "") {
$status = "⚠️ " $status = "⚠️ "
$pending = "Pending reboot (registry got $($reason.substring(2)))" $pending = "with pending reboot (registry got $($reason.substring(2)))"
} }
} }
Write-Host "$status $(hostname) is up for $(TimeSpanAsString $uptime) since $($lastBootTime.ToShortDateString()) - $pending" Write-Host "$status $(hostname) is up for $(TimeSpanAsString $uptime) since $($lastBootTime.ToShortDateString()) $pending"
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"