mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-05-31 23:45:48 +02:00
Updated write-joke.ps1
This commit is contained in:
parent
84e99a2857
commit
2a927db6ed
@ -2,7 +2,7 @@
|
|||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Writes a random joke
|
Writes a random joke
|
||||||
.DESCRIPTION
|
.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
|
.EXAMPLE
|
||||||
PS> ./write-joke.ps1
|
PS> ./write-joke.ps1
|
||||||
Chuck Norris can dribble a bowling ball. 😂
|
Chuck Norris can dribble a bowling ball. 😂
|
||||||
@ -16,12 +16,12 @@ try {
|
|||||||
$table = Import-CSV "$PSScriptRoot/../data/jokes.csv"
|
$table = Import-CSV "$PSScriptRoot/../data/jokes.csv"
|
||||||
|
|
||||||
$randomNumberGenerator = New-Object System.Random
|
$randomNumberGenerator = New-Object System.Random
|
||||||
$row = [int]$randomNumberGenerator.next(0, $table.Count - 1)
|
$rowNumber = [int]$randomNumberGenerator.next(0, $table.Count - 1)
|
||||||
$joke = $table[$row].JOKE
|
$joke = $table[$rowNumber].JOKE
|
||||||
|
|
||||||
Write-Host "`n$Joke 😂" -foregroundColor Magenta
|
Write-Host "`n$Joke 😂" -foregroundColor Green
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
} catch {
|
} catch {
|
||||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
"⚠️ Error: $($Error[0])"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user