2021-11-24 14:59:01 +01:00
|
|
|
|
<#
|
2021-11-24 14:56:38 +01:00
|
|
|
|
.SYNOPSIS
|
2021-12-01 11:01:53 +01:00
|
|
|
|
Determines the uptime
|
2021-11-24 14:56:38 +01:00
|
|
|
|
.DESCRIPTION
|
2021-12-01 11:01:53 +01:00
|
|
|
|
This script determines and says the uptime by text-to-speech (TTS).
|
2021-11-24 14:56:38 +01:00
|
|
|
|
.EXAMPLE
|
2021-12-01 11:01:53 +01:00
|
|
|
|
PS> ./check-uptime
|
2021-11-24 14:56:38 +01:00
|
|
|
|
.NOTES
|
|
|
|
|
Author: Markus Fleschutz · License: CC0
|
|
|
|
|
.LINK
|
|
|
|
|
https://github.com/fleschutz/PowerShell
|
|
|
|
|
#>
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
if ($IsLinux) {
|
|
|
|
|
$Uptime = (get-uptime)
|
|
|
|
|
} else {
|
|
|
|
|
$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 $TimeNow
|
2021-11-27 14:29:49 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$Days = $Uptime.Days
|
|
|
|
|
$Hours = $Uptime.Hours
|
|
|
|
|
$Minutes = $Uptime.Minutes
|
2021-11-24 14:56:38 +01:00
|
|
|
|
|
2021-11-27 14:29:49 +01:00
|
|
|
|
if ($Days -eq "1") {
|
2021-12-01 11:01:53 +01:00
|
|
|
|
$Reply = "Up for 1 day, "
|
2021-11-27 14:29:49 +01:00
|
|
|
|
} else {
|
2021-12-01 11:01:53 +01:00
|
|
|
|
$Reply = "Up for $Days days, "
|
2021-11-27 14:29:49 +01:00
|
|
|
|
}
|
|
|
|
|
if ($Hours -eq "1") {
|
2021-12-01 11:01:53 +01:00
|
|
|
|
$Reply += "1 hour "
|
2021-11-27 14:29:49 +01:00
|
|
|
|
} else {
|
2021-12-01 11:01:53 +01:00
|
|
|
|
$Reply += "$Hours hours "
|
2021-11-27 14:29:49 +01:00
|
|
|
|
}
|
|
|
|
|
if ($Minutes -eq "1") {
|
2021-12-01 11:01:53 +01:00
|
|
|
|
$Reply += "and 1 minute."
|
2021-11-27 14:29:49 +01:00
|
|
|
|
} else {
|
2021-12-01 11:01:53 +01:00
|
|
|
|
$Reply += "and $Minutes minutes."
|
2021-11-27 14:29:49 +01:00
|
|
|
|
}
|
2021-12-01 11:01:53 +01:00
|
|
|
|
"✔️ $Reply"
|
|
|
|
|
& "$PSScriptRoot/speak-english.ps1" "$Reply"
|
2021-11-24 14:56:38 +01:00
|
|
|
|
exit 0 # success
|
|
|
|
|
} catch {
|
|
|
|
|
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
|
|
|
|
|
exit 1
|
|
|
|
|
}
|