mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-05-30 15:08:49 +02:00
Updated write-joke.ps1
This commit is contained in:
parent
84e99a2857
commit
2a927db6ed
@ -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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user