Updated write-joke.ps1

This commit is contained in:
Markus Fleschutz 2025-05-21 15:48:39 +02:00
parent 84e99a2857
commit 2a927db6ed

View File

@ -2,7 +2,7 @@
.SYNOPSIS
Writes a random joke
.DESCRIPTION
This PowerShell script selects a random joke from Data/jokes.csv and writes it to the console.
This PowerShell script selects a random joke (from Data/jokes.csv) and writes it to the console.
.EXAMPLE
PS> ./write-joke.ps1
Chuck Norris can dribble a bowling ball. 😂
@ -16,12 +16,12 @@ try {
$table = Import-CSV "$PSScriptRoot/../data/jokes.csv"
$randomNumberGenerator = New-Object System.Random
$row = [int]$randomNumberGenerator.next(0, $table.Count - 1)
$joke = $table[$row].JOKE
$rowNumber = [int]$randomNumberGenerator.next(0, $table.Count - 1)
$joke = $table[$rowNumber].JOKE
Write-Host "`n$Joke 😂" -foregroundColor Magenta
Write-Host "`n$Joke 😂" -foregroundColor Green
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
"⚠️ Error: $($Error[0])"
exit 1
}