Update write-joke.ps1 and write-quote.ps1

This commit is contained in:
Markus Fleschutz 2023-08-25 08:08:53 +02:00
parent 175eabc661
commit bfa8c73c19
2 changed files with 12 additions and 12 deletions

View File

@ -1,11 +1,11 @@
<#
.SYNOPSIS
Writes a random Juck Norris joke to the console
Writes a random joke
.DESCRIPTION
This PowerShell script writes a random Juck Norris joke to the console.
This PowerShell script selects a random joke from Data/jokes.csv and writes it to the console.
.EXAMPLE
PS> ./write-joke
When Chuck Norris does division, there are no remainders. 😂
PS> ./write-joke.ps1
Chuck Norris can dribble a bowling ball. 😂
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
@ -13,13 +13,13 @@
#>
try {
$Table = import-csv "$PSScriptRoot/../Data/jokes.csv"
$table = Import-CSV "$PSScriptRoot/../Data/jokes.csv"
$Generator = New-Object System.Random
$Index = [int]$Generator.next(0, $Table.Count - 1)
$Joke = $Table[$Index].Joke
$randomNumberGenerator = New-Object System.Random
$row = [int]$randomNumberGenerator.next(0, $table.Count - 1)
$joke = $table[$row].JOKE
"$Joke 😂"
Write-Host "`n$Joke 😂" -foregroundColor Magenta
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"

View File

@ -1,8 +1,8 @@
<#
.SYNOPSIS
Writes a quote
Writes a random quote
.DESCRIPTION
This PowerShell script selects a random quote and prints it to the console.
This PowerShell script selects a random quote from Data/quotes.csv and writes it to the console.
.EXAMPLE
PS> ./write-quote.ps1
We must become the change we want to see.
@ -23,7 +23,7 @@ try {
$spaces = " "
$spaces = $spaces.Substring(0, $quote.Length - $author.Length)
Write-Host "`n"'“'"$quote"'„'"`n$spaces- $author"
Write-Host "`n"'“'"$quote"'„'"`n$spaces- $author" -foregroundColor Magenta
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"