Update check-time-zone.ps1 and check-uptime.ps1

This commit is contained in:
Markus Fleschutz 2023-01-08 09:56:44 +01:00
parent f7d812618b
commit 4db1c30d76
2 changed files with 13 additions and 12 deletions

View File

@ -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])"

View File

@ -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
}
}