From 4db1c30d76bb4f9879d521199c83c912e368ad38 Mon Sep 17 00:00:00 2001 From: Markus Fleschutz Date: Sun, 8 Jan 2023 09:56:44 +0100 Subject: [PATCH] Update check-time-zone.ps1 and check-uptime.ps1 --- Scripts/check-time-zone.ps1 | 6 +++--- Scripts/check-uptime.ps1 | 19 ++++++++++--------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/Scripts/check-time-zone.ps1 b/Scripts/check-time-zone.ps1 index 3cab317e..ff5ae8a2 100755 --- a/Scripts/check-time-zone.ps1 +++ b/Scripts/check-time-zone.ps1 @@ -1,8 +1,8 @@ <# .SYNOPSIS - Checks the time zone setting + Checks the time zone .DESCRIPTION - This PowerShell script determines and prints the current time zone. + This PowerShell script queries the user's time zone and prints it. .EXAMPLE PS> ./check-time-zone .LINK @@ -16,7 +16,7 @@ try { $Time = $((Get-Date).ToShortTimeString()) $TZ = (Get-Timezone) if ($TZ.SupportsDaylightSavingTime) { $DST=" & +01:00:00 DST" } else { $DST="" } - "✅ $Time in $($TZ.Id) (UTC+$($TZ.BaseUtcOffset)$DST)." + Write-Host "✅ $Time in $($TZ.Id) (UTC+$($TZ.BaseUtcOffset)$DST)." exit 0 # success } catch { "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" diff --git a/Scripts/check-uptime.ps1 b/Scripts/check-uptime.ps1 index 999b98d2..f754f0b2 100755 --- a/Scripts/check-uptime.ps1 +++ b/Scripts/check-uptime.ps1 @@ -1,8 +1,8 @@ <# .SYNOPSIS - Check uptime + Checks the uptime .DESCRIPTION - This PowerShell script queries and prints the uptime. + This PowerShell script queries the computer's uptime and prints it. .EXAMPLE PS> ./check-uptime .LINK @@ -13,34 +13,35 @@ try { if ($IsLinux) { - $Uptime = (get-uptime) + $Uptime = (Get-Uptime) } else { $BootTime = Get-WinEvent -ProviderName eventlog | Where-Object {$_.Id -eq 6005} | Select-Object TimeCreated -First 1 $Uptime = New-TimeSpan -Start $BootTime.TimeCreated.Date -End (Get-Date) } - $Days = $Uptime.Days - $Hours = $Uptime.Hours - $Minutes = $Uptime.Minutes - $Reply = "Up for " + $Days = $Uptime.Days if ($Days -eq "1") { $Reply += "1 day, " } elseif ($Days -ne "0") { $Reply += "$Days days, " } + + $Hours = $Uptime.Hours if ($Hours -eq "1") { $Reply += "1 hour, " } elseif ($Hours -ne "0") { $Reply += "$Hours hours, " } + + $Minutes = $Uptime.Minutes if ($Minutes -eq "1") { $Reply += "1 minute" } else { $Reply += "$Minutes minutes" } - "✅ $Reply." + Write-Host "✅ $Reply." exit 0 # success } catch { "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" exit 1 -} +} \ No newline at end of file