PowerShell/Scripts/tell-uptime.ps1

32 lines
846 B
PowerShell
Raw Normal View History

2021-11-24 14:59:01 +01:00
<#
2021-11-24 14:56:38 +01:00
.SYNOPSIS
Tells the uptime by text-to-speech
.DESCRIPTION
2021-11-24 14:59:01 +01:00
This script speaks the uptime version by text-to-speech (TTS).
2021-11-24 14:56:38 +01:00
.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
}
2021-11-24 15:02:54 +01:00
$Answer = "I'm up for $($Uptime.Days) days, $($Uptime.Hours) hours, $($Uptime.Minutes) minutes."
2021-11-24 14:56:38 +01:00
write-output "$Answer"
& "$PSScriptRoot/speak-english.ps1" "$Answer"
exit 0 # success
} catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
exit 1
}