Skip to content

Write-Centered

Writes text centered

param([string]$text = "")

try {
	if ($text -eq "") { $text = Read-Host "Enter the text to write" }

	$ui = (Get-Host).ui
	$rui = $ui.rawui 
	[int]$numSpaces = ($rui.MaxWindowSize.Width - $text.Length) / 2

	[string]$spaces = ""
	for ([int]$i = 0; $i -lt $numSpaces; $i++) { $spaces += " " }
	Write-Host "$spaces$text"
	exit 0 # success
} catch {
	"?? ERROR: $($Error[0]) (script line $($_.InvocationInfo.ScriptLineNumber))"
	exit 1
}

Specifies the text to write

An interactive directory of PowerShell scripts.