Skip to content

Write-Animated

Writes animated text

param([string]$text = "Welcome to PowerShell", [int]$speed = 10) # 10ms

function WriteLine([string]$line) {
	[int]$end = $line.Length
	$startPos = $HOST.UI.RawUI.CursorPosition
	$spaces = "                                                                     "
	[int]$termHalfWidth = 120 / 2
	foreach($pos in 1 .. $end) {
		$HOST.UI.RawUI.CursorPosition = $startPos
		Write-Host "$($spaces.Substring(0, $termHalfWidth - $pos / 2) + $line.Substring(0, $pos))" -noNewline
		Start-Sleep -milliseconds $speed
	}
	Write-Host ""
}

try {
	WriteLine $text 
	exit 0 # success
} catch {
	"?? ERROR: $($Error[0]) (script line $($_.InvocationInfo.ScriptLineNumber))"
        exit 1
}

Specifies the text line to write ("Welcome to PowerShell" by default)

Specifies the animation speed per character (10ms by default)

An interactive directory of PowerShell scripts.