Update check-uptime.ps1

This commit is contained in:
Markus Fleschutz 2022-10-21 18:05:08 +02:00
parent 45c1b1e235
commit 3feaace049

View File

@ -1,8 +1,8 @@
<# <#
.SYNOPSIS .SYNOPSIS
Determines the uptime Check uptime
.DESCRIPTION .DESCRIPTION
This PowerShell script determines and says the uptime by text-to-speech (TTS). This PowerShell script queries and prints the uptime.
.EXAMPLE .EXAMPLE
PS> ./check-uptime PS> ./check-uptime
.LINK .LINK
@ -16,8 +16,7 @@ try {
$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
$TimeNow = Get-Date $Uptime = New-TimeSpan -Start $BootTime.TimeCreated.Date -End (Get-Date)
$Uptime = New-TimeSpan -Start $BootTime.TimeCreated.Date -End $TimeNow
} }
$Days = $Uptime.Days $Days = $Uptime.Days
$Hours = $Uptime.Hours $Hours = $Uptime.Hours
@ -30,14 +29,14 @@ try {
$Reply += "$Days days, " $Reply += "$Days days, "
} }
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, "
} }
if ($Minutes -eq "1") { if ($Minutes -eq "1") {
$Reply += "and 1 minute" $Reply += "1 minute"
} elseif ($Minutes -ne "0") { } else {
$Reply += "and $Minutes minutes" $Reply += "$Minutes minutes"
} }
"$Reply." "$Reply."
exit 0 # success exit 0 # success