From 1e6d5ac3a5571ded98a986e96a07b705e11e8153 Mon Sep 17 00:00:00 2001 From: Markus Fleschutz Date: Wed, 21 Feb 2024 16:32:16 +0100 Subject: [PATCH] Updated check-uptime.ps1 --- scripts/check-uptime.ps1 | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/scripts/check-uptime.ps1 b/scripts/check-uptime.ps1 index 794f5d36..73c635af 100755 --- a/scripts/check-uptime.ps1 +++ b/scripts/check-uptime.ps1 @@ -12,7 +12,7 @@ Author: Markus Fleschutz | License: CC0 #> -function TimeSpan2String([TimeSpan]$uptime) +function TimeSpanAsString([TimeSpan]$uptime) { [int]$days = $uptime.Days [int]$hours = $days * 24 + $uptime.Hours @@ -26,16 +26,15 @@ function TimeSpan2String([TimeSpan]$uptime) } try { - $hostname = $(hostname) + [system.threading.thread]::currentthread.currentculture = [system.globalization.cultureinfo]"en-US" if ($IsLinux) { + $lastBootTime = (Get-Uptime -since) $uptime = (Get-Uptime) - Write-Host "✅ $hostname is up for $(TimeSpan2String $uptime)" } else { - [system.threading.thread]::currentthread.currentculture = [system.globalization.cultureinfo]"en-US" $lastBootTime = (Get-CimInstance Win32_OperatingSystem).LastBootUpTime $uptime = New-TimeSpan -Start $lastBootTime -End (Get-Date) - Write-Host "✅ $hostname is up for $(TimeSpan2String $uptime) since $($lastBootTime.ToShortDateString())" } + Write-Host "✅ $(hostname) is up for $(TimeSpanAsString $uptime) since $($lastBootTime.ToShortDateString())" exit 0 # success } catch { "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"