PowerShell/scripts/write-headline.ps1

32 lines
741 B
PowerShell
Raw Normal View History

2024-10-01 15:24:16 +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
-----------------
2024-04-21 17:09:15 +02:00
.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
[int]$len = $text.Length
[string]$line = "------"
2024-04-21 17:09:15 +02:00
for ([int]$i = 0; $i -lt $len; $i++) { $line += "-" }
Write-Host "`n$line`n $text`n$line" -foregroundColor green
2024-04-21 17:09:15 +02:00
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}