Update write-quote.ps1

This commit is contained in:
Markus Fleschutz 2023-08-16 07:12:53 +02:00
parent f78fc2ed9f
commit 613a18f40f

View File

@ -1,10 +1,12 @@
<# <#
.SYNOPSIS .SYNOPSIS
Writes a quote to the console Writes a quote
.DESCRIPTION .DESCRIPTION
This PowerShell script writes a random quote to the console. This PowerShell script selects a random quote and prints it to the console.
.EXAMPLE .EXAMPLE
PS> ./write-quote PS> ./write-quote.ps1
We must become the change we want to see.
- MAHATMA GANDHI
.LINK .LINK
https://github.com/fleschutz/PowerShell https://github.com/fleschutz/PowerShell
.NOTES .NOTES
@ -12,18 +14,16 @@
#> #>
try { try {
$Table = Import-CSV "$PSScriptRoot/../Data/quotes.csv" $table = Import-CSV "$PSScriptRoot/../Data/quotes.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)
$Quote = $Table[$Index].QUOTE $quote = $table[$row].QUOTE
$Author = $Table[$Index].AUTHOR $author = $table[$row].AUTHOR.toUpper()
$spaces = " "
$spaces = $spaces.Substring(0, $quote.Length - $author.Length)
Write-Output "" Write-Host "`n"'“'"$quote"'„'"`n$spaces- $author"
Write-Host '“'"$Quote"'„'
$Spaces = " "
$Spaces = $Spaces.Substring(0, $Quote.Length - $Author.Length)
Write-Output "$Spaces- $($Author.toUpper())"
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"