Powershell Notes to Self

Inline text updating:
Lazy way of having a progress indicator that doesn’t fill the whole screen history and doesn’t require Write-Progress. Use NoNewline to avoid implicit newline/carriage return, then manually add a carriage return (`r) at the start of your line to overwrite existing text.

Note: if your text is variable length you can use a pre-emptive set of control chars to clear the line and reset the cursor

Write-Host "`r$TimestampOrWhatever: $ValueOrWhatever" -NoNewline


Write-Host "$([char]27)[2K`r" -NoNewline #Equivalent to Esc[2K
Write-Host "$TimestampOrWhatever: $ValueOrWhatever" -NoNewline

Leave a Reply

Your email address will not be published. Required fields are marked *