1

The color for '$obj | Out-Default' is always white. Write-Host lets you select -ForegroundColor * -BackgroundColor. But it doesn't show the object nice.

Test object

$obj = [PSCustomObject]@{ 
                String = "A"
                Num = 6
     }

out-default

String Num
------ ---
A        6

write-host

@{String=A; Num=6}
mklement0
  • 382,024
  • 64
  • 607
  • 775
deetle
  • 197
  • 8
  • 2
    Use `Write-Host` in conjunction with `Out-String`: `Write-Host $($obj |Out-String) -ForegroundColor Cyan` – Mathias R. Jessen Jun 17 '22 at 17:03
  • 1
    Does this answer your question? [Powershell - Output Color for certain results](https://stackoverflow.com/questions/46016763/powershell-output-color-for-certain-results) – Abraham Zinala Jun 17 '22 at 18:07

1 Answers1

4

This is not my answer, it is Mathias R. Jessen's.

Use Write-Host in conjunction with Out-String; e.g.:

Write-Host ($obj |Out-String) -ForegroundColor Cyan
mklement0
  • 382,024
  • 64
  • 607
  • 775
deetle
  • 197
  • 8