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 .SYNOPSIS
Checks the time zone setting Checks the time zone
.DESCRIPTION .DESCRIPTION
This PowerShell script determines and prints the current time zone. This PowerShell script queries the user's time zone and prints it.
.EXAMPLE .EXAMPLE
PS> ./check-time-zone PS> ./check-time-zone
.LINK .LINK
@ -16,7 +16,7 @@ try {
$Time = $((Get-Date).ToShortTimeString()) $Time = $((Get-Date).ToShortTimeString())
$TZ = (Get-Timezone) $TZ = (Get-Timezone)
if ($TZ.SupportsDaylightSavingTime) { $DST=" & +01:00:00 DST" } else { $DST="" } 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 exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"

View File

@ -1,8 +1,8 @@
<# <#
.SYNOPSIS .SYNOPSIS
Check uptime Checks the uptime
.DESCRIPTION .DESCRIPTION
This PowerShell script queries and prints the uptime. This PowerShell script queries the computer's uptime and prints it.
.EXAMPLE .EXAMPLE
PS> ./check-uptime PS> ./check-uptime
.LINK .LINK
@ -13,34 +13,35 @@
try { try {
if ($IsLinux) { if ($IsLinux) {
$Uptime = (get-uptime) $Uptime = (Get-Uptime)
} else { } else {
$BootTime = Get-WinEvent -ProviderName eventlog | Where-Object {$_.Id -eq 6005} | Select-Object TimeCreated -First 1 $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) $Uptime = New-TimeSpan -Start $BootTime.TimeCreated.Date -End (Get-Date)
} }
$Days = $Uptime.Days
$Hours = $Uptime.Hours
$Minutes = $Uptime.Minutes
$Reply = "Up for " $Reply = "Up for "
$Days = $Uptime.Days
if ($Days -eq "1") { if ($Days -eq "1") {
$Reply += "1 day, " $Reply += "1 day, "
} elseif ($Days -ne "0") { } elseif ($Days -ne "0") {
$Reply += "$Days days, " $Reply += "$Days days, "
} }
$Hours = $Uptime.Hours
if ($Hours -eq "1") { if ($Hours -eq "1") {
$Reply += "1 hour, " $Reply += "1 hour, "
} elseif ($Hours -ne "0") { } elseif ($Hours -ne "0") {
$Reply += "$Hours hours, " $Reply += "$Hours hours, "
} }
$Minutes = $Uptime.Minutes
if ($Minutes -eq "1") { if ($Minutes -eq "1") {
$Reply += "1 minute" $Reply += "1 minute"
} else { } else {
$Reply += "$Minutes minutes" $Reply += "$Minutes minutes"
} }
"$Reply." Write-Host "$Reply."
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }