Improved next-jokes.ps1

This commit is contained in:
Markus Fleschutz
2021-01-29 12:27:04 +01:00
parent 463403eea1
commit 9a6f637efa
2 changed files with 78 additions and 3 deletions

View File

@ -7,9 +7,15 @@
#>
try {
$Response = (invoke-webRequest http://api.icndb.com/jokes/random).Content | ConvertFrom-Json
$Joke = $Response.value.joke
write-output "$Text"
$PathToRepo = "$PSScriptRoot/.."
$Table = import-csv "$PathToRepo/Data/jokes.csv"
$Generator = New-Object System.Random
$Index = [int]$Generator.next(0,66)
$Joke = $Table[$Index].Joke
write-output "$Joke"
exit 0
} catch {
write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"