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
|
.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])"
|
||||||
|
@ -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
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user