Skip to content

PSStyle.OutputRendering = "PlainText" or NO_COLOR not working, need to use __SuppressAnsiEscapeSequences #19188

@castortech

Description

@castortech

Prerequisites

Steps to reproduce

First off this issue doesn't appear if running the script from a terminal in VSCode

But I am launching PS scripts from Java and passing values for both PSStyle.OutputRendering & NO_COLOR and I'm able to see that the values are there if I output them during execution.

But the following, which here throws an exception since the store doesn't exist, will produce some Ansi code:
Get-SecretVault -Name xxStore | ConvertTo-Json

Finally found this issue and decided to also set the __SuppressAnsiEscapeSequences and everything started to work correctly. I would have expected that the other variants would have set that variable, but again showing during execution, it wasn't set, unless I passed the value manually.

Expected behavior

Get-SecretVault: C:\Users\XXXX\AppData\Local\Temp\psscript_167700463450917082999875903795167.ps1:15
Line |
  15 |  Get-SecretVault -Name xxStore | ConvertTo-Json
     |  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Vault xxStore does not exist in registry.

Actual behavior

�[31;1mGet-SecretVault: �[0mC:\Users\XXXXX\AppData\Local\Temp\psscript_16770047511711965109290211120660.ps1:15�[0m
�[31;1m�[0m�[36;1mLine |�[0m
�[31;1m�[0m�[36;1m�[36;1m  15 | �[0m �[36;1mGet-SecretVault -Name xxStore�[0m | ConvertTo-Json�[0m
�[31;1m�[0m�[36;1m�[36;1m�[0m�[36;1m�[0m�[36;1m     | �[31;1m ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~�[0m
�[31;1m�[0m�[36;1m�[36;1m�[0m�[36;1m�[0m�[36;1m�[31;1m�[31;1m�[36;1m     | �[31;1mVault xxStore does not exist in registry.�[0m

Error details

No response

Environment data

Name                           Value
----                           -----
PSVersion                      7.3.2
PSEdition                      Core
GitCommitId                    7.3.2
OS                             Microsoft Windows 10.0.19044
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions