Add tell-uptime.ps1

This commit is contained in:
Markus Fleschutz 2021-11-24 14:56:38 +01:00
parent 01e333675d
commit 359745781e
2 changed files with 32 additions and 0 deletions

View File

@ -98,3 +98,4 @@ Nice Conversation
* *Computer, tell joke.*
* *Computer, tell quote.*
* *Computer, tell operating system.*
* *Computer, tell up-time.*

31
Scripts/tell-uptime.ps1 Executable file
View File

@ -0,0 +1,31 @@

.SYNOPSIS
Tells the uptime by text-to-speech
.DESCRIPTION
G This script speaks the uptime version by text-to-speech (TTS).
.EXAMPLE
PS> ./tell-uptime
.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
}
$Answer = "$($Uptime.Days) days, $($Uptime.Hours) hours, $($Uptime.Minutes) minutes."
write-output "$Answer"
& "$PSScriptRoot/speak-english.ps1" "$Answer"
exit 0 # success
} catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
exit 1
}