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

View File

@ -1,8 +1,8 @@
<# <#
.SYNOPSIS .SYNOPSIS
Writes a quote Writes a random quote
.DESCRIPTION .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 .EXAMPLE
PS> ./write-quote.ps1 PS> ./write-quote.ps1
We must become the change we want to see. We must become the change we want to see.
@ -23,7 +23,7 @@ try {
$spaces = " " $spaces = " "
$spaces = $spaces.Substring(0, $quote.Length - $author.Length) $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 exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"