PowerShell/scripts/write-headline.ps1

33 lines
745 B
PowerShell
Raw Normal View History

2024-10-01 13:37:53 +02:00
<#
2024-04-21 17:09:15 +02:00
.SYNOPSIS
2024-04-21 17:23:21 +02:00
Writes a headline
2024-04-21 17:09:15 +02:00
.DESCRIPTION
This PowerShell script writes the given text as a headline.
.PARAMETER text
2024-04-21 17:23:21 +02:00
Specifies the text to write
2024-04-21 17:09:15 +02:00
.EXAMPLE
PS> ./write-headline.ps1 "Hello World"
* Hello World *
---------------
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
param([string]$text = "")
2024-04-21 17:23:21 +02:00
2024-04-21 17:09:15 +02:00
try {
2024-04-21 17:23:21 +02:00
if ($text -eq "") { $text = Read-Host "Enter the text to write" }
2024-04-21 17:09:15 +02:00
Write-Host "`n* $text *" -foregroundColor green
[int]$len = $text.Length
[string]$line = "----"
for ([int]$i = 0; $i -lt $len; $i++) { $line += "-" }
Write-Host "$line" -foregroundColor green
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}