Powershell Inline Status Updates Without Write-Progress

Here’s a 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.

The magic “$([char]27[2K`r” (Escape[2K) is an ANSI control sequence that tells the terminal to preemptively erase the entire line so that you don’t end up with leftover characters if your next value is shorter than the previous one. https://www.real-world-systems.com/docs/ANSIcode.html#CSI

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 *