mirror of
https://github.com/fleschutz/PowerShell.git
synced 2024-12-15 19:21:04 +01:00
Update check-time-zone.ps1 and check-uptime.ps1
This commit is contained in:
parent
f7d812618b
commit
4db1c30d76
@ -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])"
|
||||
|
@ -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,32 +13,33 @@
|
||||
|
||||
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])"
|
||||
|
Loading…
Reference in New Issue
Block a user