2024-10-01 15:24:16 +02:00
|
|
|
|
<#
|
2021-07-13 21:10:02 +02:00
|
|
|
|
.SYNOPSIS
|
2023-08-25 08:08:53 +02:00
|
|
|
|
Writes a random joke
|
2021-07-13 21:10:02 +02:00
|
|
|
|
.DESCRIPTION
|
2023-08-25 08:08:53 +02:00
|
|
|
|
This PowerShell script selects a random joke from Data/jokes.csv and writes it to the console.
|
2021-07-13 21:10:02 +02:00
|
|
|
|
.EXAMPLE
|
2023-08-25 08:08:53 +02:00
|
|
|
|
PS> ./write-joke.ps1
|
|
|
|
|
Chuck Norris can dribble a bowling ball. 😂
|
2021-07-13 21:10:02 +02:00
|
|
|
|
.LINK
|
|
|
|
|
https://github.com/fleschutz/PowerShell
|
2022-09-06 21:42:04 +02:00
|
|
|
|
.NOTES
|
|
|
|
|
Author: Markus Fleschutz | License: CC0
|
2021-01-12 17:06:35 +01:00
|
|
|
|
#>
|
|
|
|
|
|
|
|
|
|
try {
|
2023-10-31 11:25:11 +01:00
|
|
|
|
$table = Import-CSV "$PSScriptRoot/../data/jokes.csv"
|
2021-01-29 12:27:04 +01:00
|
|
|
|
|
2023-08-25 08:08:53 +02:00
|
|
|
|
$randomNumberGenerator = New-Object System.Random
|
|
|
|
|
$row = [int]$randomNumberGenerator.next(0, $table.Count - 1)
|
|
|
|
|
$joke = $table[$row].JOKE
|
2021-08-08 11:02:12 +02:00
|
|
|
|
|
2023-08-25 08:08:53 +02:00
|
|
|
|
Write-Host "`n$Joke 😂" -foregroundColor Magenta
|
2021-09-27 10:09:45 +02:00
|
|
|
|
exit 0 # success
|
2021-01-12 17:06:35 +01:00
|
|
|
|
} catch {
|
2022-04-13 12:06:32 +02:00
|
|
|
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
2021-01-12 17:06:35 +01:00
|
|
|
|
exit 1
|
|
|
|
|
}
|