46 lines
1.0 KiB
PowerShell
46 lines
1.0 KiB
PowerShell
function Get-SwansonQuote {
|
|
param(
|
|
[int]$Level = 1
|
|
)
|
|
|
|
for($i = 0; $i -lt $level; $i++) {
|
|
try {
|
|
Write-Output (Invoke-RestMethod 'http://ron-swanson-quotes.herokuapp.com/v2/quotes' -Method Get).Trim()
|
|
}
|
|
catch {
|
|
Write-Warning "Failed attempt $i : $_"
|
|
}
|
|
}
|
|
}
|
|
|
|
function Talk-Back {
|
|
[CmdletBinding()]
|
|
param(
|
|
[Parameter(ValueFromPipeline)]
|
|
[string]$Quote
|
|
)
|
|
Begin {
|
|
Write-Verbose "Begin!"
|
|
$voice = New-Object -ComObject "SAPI.SPvoice"
|
|
}
|
|
|
|
Process {
|
|
Write-Verbose $quote
|
|
$voice.speak($Quote) | Out-Null
|
|
}
|
|
|
|
End {
|
|
Write-Verbose "End!"
|
|
Remove-Variable Voice
|
|
}
|
|
}
|
|
|
|
function Get-Inspiration {
|
|
param(
|
|
[int]$Count
|
|
)
|
|
|
|
Get-SwansonQuote -Level $Count | Talk-Back -Verbose
|
|
}
|
|
|
|
Get-Inspiration -Count 3 |