PowerShell/scripts/write-quote.ps1

33 lines
1.0 KiB
PowerShell
Raw Normal View History

2024-10-01 13:37:53 +02:00
<#
.SYNOPSIS
Writes a random quote
2021-10-04 21:29:23 +02:00
.DESCRIPTION
2024-05-06 17:42:12 +02:00
This PowerShell script selects a random quote from .../data/quotes.csv and writes it to the console.
.EXAMPLE
2023-08-16 07:12:53 +02:00
PS> ./write-quote.ps1
We must become the change we want to see.
2024-05-06 17:42:12 +02:00
- Mahatma Gandhi
.LINK
https://github.com/fleschutz/PowerShell
2022-09-06 21:42:04 +02:00
.NOTES
Author: Markus Fleschutz | License: CC0
#>
try {
2023-10-31 11:25:11 +01:00
$table = Import-CSV "$PSScriptRoot/../data/quotes.csv"
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
2024-05-06 17:42:12 +02:00
$author = $table[$row].AUTHOR
2023-08-16 07:12:53 +02:00
$spaces = " "
$spaces = $spaces.Substring(0, $quote.Length - $author.Length)
2024-05-06 17:42:12 +02:00
Write-Host "`n"'“'"$quote"'„'"" -foregroundColor Green
Write-Host "$spaces- $author" -foregroundColor Blue
2021-09-27 10:09:45 +02:00
exit 0 # success
} catch {
2022-04-13 12:06:32 +02:00
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}