2021-09-27 10:38:12 +02:00
|
|
|
|
<#
|
2021-08-05 14:53:40 +02:00
|
|
|
|
.SYNOPSIS
|
2023-08-25 08:08:53 +02:00
|
|
|
|
Writes a random quote
|
2021-10-04 21:29:23 +02:00
|
|
|
|
.DESCRIPTION
|
2023-08-25 08:08:53 +02:00
|
|
|
|
This PowerShell script selects a random quote from Data/quotes.csv and writes it to the console.
|
2021-08-05 14:53:40 +02:00
|
|
|
|
.EXAMPLE
|
2023-08-16 07:12:53 +02:00
|
|
|
|
PS> ./write-quote.ps1
|
|
|
|
|
“ We must become the change we want to see. „
|
|
|
|
|
- MAHATMA GANDHI
|
2021-08-05 14:53:40 +02:00
|
|
|
|
.LINK
|
|
|
|
|
https://github.com/fleschutz/PowerShell
|
2022-09-06 21:42:04 +02:00
|
|
|
|
.NOTES
|
|
|
|
|
Author: Markus Fleschutz | License: CC0
|
2021-08-05 14:53:40 +02:00
|
|
|
|
#>
|
|
|
|
|
|
|
|
|
|
try {
|
2023-08-16 07:12:53 +02:00
|
|
|
|
$table = Import-CSV "$PSScriptRoot/../Data/quotes.csv"
|
2021-08-05 14:53:40 +02:00
|
|
|
|
|
2023-08-16 07:12:53 +02:00
|
|
|
|
$randomNumberGenerator = New-Object System.Random
|
|
|
|
|
$row = [int]$randomNumberGenerator.next(0, $table.Count - 1)
|
|
|
|
|
$quote = $table[$row].QUOTE
|
|
|
|
|
$author = $table[$row].AUTHOR.toUpper()
|
|
|
|
|
$spaces = " "
|
|
|
|
|
$spaces = $spaces.Substring(0, $quote.Length - $author.Length)
|
2021-08-05 14:53:40 +02:00
|
|
|
|
|
2023-08-25 08:08:53 +02:00
|
|
|
|
Write-Host "`n"'“'"$quote"'„'"`n$spaces- $author" -foregroundColor Magenta
|
2021-09-27 10:09:45 +02:00
|
|
|
|
exit 0 # success
|
2021-08-05 14:53:40 +02:00
|
|
|
|
} catch {
|
2022-04-13 12:06:32 +02:00
|
|
|
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
2021-08-05 14:53:40 +02:00
|
|
|
|
exit 1
|
|
|
|
|
}
|