Why Aren't ANSI Escape Codes Working in PowerShell?

September 13, 2025 1 answer
Asked by CuriousCat987
Hey everyone, I'm having some trouble with ANSI escape codes in PowerShell. They don't seem to render correctly when I'm using **Select-String** in the main PowerShell console, but they work just fine in the VS Code terminal. I noticed that if I assign the output of a command to a variable, like in `$a = yt-dlp --help; $a | sls config`, it displays correctly. I'm not sure if this is a bug or if I've done something wrong. Would appreciate any insights!

Answers

TechWhiz24
What OS are you on? It looks like your PowerShell window might be running in conhost.exe, which is the default on older systems. This version didn't support ANSI escape codes until Windows 10. If youโ€™re on an older OS, that could be the issue. You might want to try using Windows Terminal, which offers better support, but you'll need at least Win10 version 1904.

CuriousCat987: I'm on Windows 11 home 22H2. But as I mentioned, when I assign the output to a variable, it works as expected. Just sharing the example again.

Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions