PowerShell / PowerShell/PowerShell

`Write-Host`'s `--*groundColor` doesn't work when inside an instance piped to another command

Open
#19,840 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Needs-Triage
Dominant language
C#
Stars
55.5k
Forks
8.5k
Avg merge
1d 2h
Merged PRs (30d)
88

Description

Prerequisites
Steps to reproduce

From outside powershell, run a powershell script that produces colours using Write-Host --ForegroundColor, and then pipe that output for further processing.

In the attached image I show

  1. coloured text can be pushed through Write-Host, even if the output is processed
  2. coloured text can be generated by Write-Host --*groundColor, if not post-processed
  3. coloured text cannot make it out from Write-Host --*groundColor, if post-processed
  4. same as test 1, but manual
Expected behavior
Colours are maintained.
Actual behavior
Colours are not maintained.
Error details

No response

Environment data
PSVersion                      7.3.4
PSEdition                      Core
GitCommitId                    7.3.4
OS                             Linux 5.10.0-19-amd64 #1 SMP Debian 5.10.149-2 (2022-10-21)
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
Visuals

image

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the reported behavior on PowerShell 7.3.4 on Linux using Write-Host with --ForegroundColor or --BackgroundColor inside a pipeline, then compare it with unprocessed output. The issue names no source files or tests, so trace Write-Host's color handling and pipeline serialization before determining how to verify that colours are maintained after processing.

Written by the indexing model from the issue text.

Assessment

Tech stack
powershell
Domain
cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.