Ansi Escape Codes and PowerShell 7.2.1

I have a series of scripts that out use “out-file” cmdlet to output a variable to a text file. After an upgrade to PS 7.2.1, I started getting a series of strange characters in the output of the text file. After a little investigation, these appear to be ANSI Escape Codes as far as I can tell.

Even a simple AD command shows this issue

get-aduser ******* | Out-file “C:\ps\file.txt”

e[32;1mDistinguishedName : e[0mCN= *******
e[32;1mEnabled : e[0mTrue
e[32;1mGivenName : e[0m***
e[32;1mName : e[0m************
e[32;1mObjectClass : e[0muser
e[32;1mObjectGUID : e[0mGUID*
e[32;1mSamAccountName : e[0m******
e[32;1mSID : e[0mSID
e[32;1mSurname : e[0m*******
e[32;1mUserPrincipalName : e[0m*******.com

Note: User information has been obscured with asterisks (*****)

you see the recurring patterns of e[32;1m and e[0m

This does NOT occur in earlier versions of PS.

At first I thought it might be an encoding issue, but I’ve tried every available encoding scheme (out-file -encoding ASCII/UTF8/Unicode/ et al) with the same results. Any ideas here?

Thank you for your help!

Just an FYI, I do not see this behavior. I get valid output

ugh…ok…we’re seeing this across multiple machines in the environment. Wonder what we have going on. Thanks for the insight.

I just ran get-process | Out-file on a test Windows 11 box that’s not on the domain with the same results…I’m seeing the ansi escape codes as well in the header. Displays properly in the console…just the associated output text file that has the goofy characters.

Also just fired up a brand new windows 10 VM that’s never been used / Not on domain, downloaded PS 7.2.1 x64 from Github, and ran get-process | Out-file C:\file.txt

Console shows correctly. The output text file has the issues.

Headers show the escape characters:
e[32;1m NPM(K) PM(M) WS(M) CPU(s) Id SI ProcessNamee[0m
e[32;1m ------ ----- ----- ------ – – -----------e[0m

Anyone else see this?

Yep, I can replicate that. Someone has already reported it:


Matt, aka “replication man”

1 Like

Thanks for the validation. Appreciate your time with this.