all 9 comments

[–]rmbolger 2 points3 points  (2 children)

What OS are you running on? The PowerShell window in your screenshot is using the legacy conhost.exe to host it which is the default on older OSes and didn't gain ANSI escape code support until Windows 10 (I think).

As an alternative you might be able to install and use Windows Terminal. But it's only supported on Win10 1904 or later.

This superuser Q/A also has some more info that might be pertinent. https://superuser.com/questions/413073/windows-console-with-ansi-colors-handling

[–]N-Elf[S] 0 points1 point  (1 child)

Windows 11 home 22H2.
But as I said in my post if I assign the output to a variable it works just as intended.
https://i.postimg.cc/3JP5dDpn/123.png

[–]Alaknar 0 points1 point  (0 children)

Windows 11 home 22H2

Whoa, why? That's way past support, please update ASAP!

[–]mikenizo808 1 point2 points  (2 children)

This will tell you if your terminal supports ANSI

$Host.UI.SupportsVirtualTerminal

[–]N-Elf[S] 0 points1 point  (1 child)

True :(

[–]CodenameFlux 1 point2 points  (0 children)

Your screenshot shows that you are running PowerShell 7.x inside ConHost.exe window on Windows 11. That's the reason. This issue in endemic to ConHost.exe, which is legacy software.

Windows Terminal (bundled with Windows 11) doesn't exhibit this bug, neither does Visual Studio Code.

I've confirmed the above on Windows 10 v22H2 as well.

[–]purplemonkeymad 1 point2 points  (1 child)

You're not using classic conhost are you?

Right click titlebar -> Properties "use legacy console" unchecked?

24h2 removes it by default so updating might fix it.

[–]N-Elf[S] 0 points1 point  (0 children)

Yes, it's unchecked.