-
-
Notifications
You must be signed in to change notification settings - Fork 545
Expand file tree
/
Copy pathwrite-joke.ps1
More file actions
executable file
·27 lines (24 loc) · 708 Bytes
/
write-joke.ps1
File metadata and controls
executable file
·27 lines (24 loc) · 708 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<#
.SYNOPSIS
Writes a random joke
.DESCRIPTION
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. 😂
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
try {
$table = Import-CSV "$PSScriptRoot/data/jokes.csv"
$randomNumberGenerator = New-Object System.Random
$rowNumber = [int]$randomNumberGenerator.next(0, $table.Count - 1)
$joke = $table[$rowNumber].JOKE
Write-Host "`n$Joke 😂" -foregroundColor Green
exit 0 # success
} catch {
"⚠️ ERROR: $($Error[0]) (script line $($_.InvocationInfo.ScriptLineNumber))"
exit 1
}