You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using out-file with or without specifying any encoding the file has some weird characters at the beginning of the file
�[32;1m NPM(K) PM(M) WS(M) CPU(s) Id SI ProcessName�[0m
�[32;1m ------ ----- ----- ------ -- -- -----------�[0m
I've tried this on different computers all using ps 7.2.1, windows 10, server 2016 etc. When using the same get-process |out-file with powershell 5.1 it works as expected without those characters.
Expected behavior
NPM(K) PM(M) WS(M) CPU(s) Id SI ProcessName
Actual behavior
�[32;1m NPM(K) PM(M) WS(M) CPU(s) Id SI ProcessName�[0m
This is because ls itself knows when it is being redirected and omits the VT. PS7.2 handles this at the shell level due to things like formatting which happens within the PS engine. If you run ls -G > out.txt within PS7.2, you'll still see that VT is omitted because ls decided to omit it.
I think the way to address this issue while addressing PowerShell/Announcements#28 is to change the current regex for removing VT to have a fixed list of known VT codes that will be removed. This would still need to go through a security review to ensure spoofing doesn't happen.
Steve Lee (@SteveL-MSFT) this is particularly annoying when $PSStyle is doing full filename coloring and piping the output to clip.exe. It seems like I'm doing that with increasing frequency and pasting into Teams... 😔
JohnMarkHowell Sorry, I pasted an older attempt! Too many tabs open. This one is the one that fixed me. $PSStyle.OutputRendering = [System.Management.Automation.OutputRendering]::PlainText
Out-File takes the format of the input object, so this strips any escape sequences out of my psobjects.
Activity
vexx32 commentedon Jan 11, 2022
/cc Steve Lee (@SteveL-MSFT)
237dmitry commentedon Jan 11, 2022
computechrr commentedon Jan 11, 2022
computechrr commentedon Jan 11, 2022
LeeHolmes commentedon Jan 27, 2022
This is a pretty major breaking change. This doesn't happen with other ANSI shells, such as Bash:
SteveL-MSFT commentedon Jan 27, 2022
This is because
lsitself knows when it is being redirected and omits the VT. PS7.2 handles this at the shell level due to things like formatting which happens within the PS engine. If you runls -G > out.txtwithin PS7.2, you'll still see that VT is omitted becauselsdecided to omit it.I think the way to address this issue while addressing PowerShell/Announcements#28 is to change the current regex for removing VT to have a fixed list of known VT codes that will be removed. This would still need to go through a security review to ensure spoofing doesn't happen.
gwojan commentedon Jan 27, 2022
Steve Lee (@SteveL-MSFT) this is particularly annoying when
$PSStyleis doing full filename coloring and piping the output toclip.exe. It seems like I'm doing that with increasing frequency and pasting into Teams... 😔JohnMarkHowell commentedon May 30, 2022
Still happening in v7.4.2
Any suggestions other than always using a replace filter before the
Out-File?JasonDTX commentedon Jul 28, 2022
You may find some success using ascii as the default encoding for the entire session.
$OutputEncoding = [Text.Encoding]::ASCIISorry if this was already tried, it helped with my out-file encoding in pwsh 7
JohnMarkHowell commentedon Jul 28, 2022
GitHub_User_5678309 (@JasonDTX) - I just tried that and it did not alter the output (meaning the output still included escape characters).
JohnMarkHowell commentedon Jul 28, 2022
Steve Lee (@SteveL-MSFT), Paul Higinbotham (@PaulHigin) - This still happens in 7.2.5 on Windows 11
JasonDTX commentedon Jul 28, 2022
JohnMarkHowell Sorry, I pasted an older attempt! Too many tabs open. This one is the one that fixed me.
$PSStyle.OutputRendering = [System.Management.Automation.OutputRendering]::PlainTextOut-File takes the format of the input object, so this strips any escape sequences out of my psobjects.
JohnMarkHowell commentedon Jul 28, 2022
That is awesome, GitHub_User_5678309 (@JasonDTX) ! That fixed it! Thank you!!!!!!!