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)
}
$status = ""
$pending = "No pending reboot"
$pending = ""
if ($IsLinux) {
if (Test-Path "/var/run/reboot-required") {
$status = "⚠️ "
$pending = "Pending reboot (found: /var/run/reboot-required)"
$pending = "with pending reboot (found /var/run/reboot-required)"
}
} else {
$reason = ""
@ -84,10 +84,10 @@ try {
}
if ($reason -ne "") {
$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
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"