6

I'm wondering if it's possible to write some coloured-text in orange with Write-Host (or with another PowerShell Cmdlet).

It seems Orange is not an available color for the -ForegroundColor parameter, but commands like Write-Warning are able to display something in orange.

Jérôme
  • 26,567
  • 29
  • 98
  • 120
  • Try DarkYellow, however for me this doesn't seem to work... – Bogdan Kuštan Jan 28 '15 at 08:32
  • Keep in mind that using a specific color could cause problems, because you can't make assumptions about the user's background color, so you can end up with something unreadable. – Will I Am Dec 10 '20 at 21:51

2 Answers2

1

Found what appears to be Write-Host code here: Powershell-Misc/Write-Host.ps1 at master · beatcracker/Powershell-Misc · GitHub

Found ANSI escape codes here: ANSI escape code - Wikipedia

Found color orange here: RGB Color Codes Chart

Built this code based on info taken from the above:

$Esc = [char]27
$Ansi24BitTemplate = "$Esc[{0};2;{1};{2};{3}m"
$Ansi24BitFore = '38'
$Ansi24BitBack = '48'
$OrangeForeColor = $Ansi24BitTemplate -f $Ansi24BitFore, 255, 165, 0
$OrangeBackColor = $Ansi24BitTemplate -f $Ansi24BitBack, 255, 165, 0

Write-Host "$($OrangeBackColor)Testing" -ForegroundColor Black
Write-Host "$($OrangeForeColor)Testing" -BackgroundColor Black

Which gave this output:

enter image description here

NOTE: This will not work on some older equipment and in some situations. But I believe it will work in the majority of Windows 10 computer.

Darin
  • 1,423
  • 1
  • 10
  • 12
0

You can change the PowerShell colors via the registry at HKCU\Console in the ColorTable00-ColorTable15 keys. There are only sixteen colors available though, so you will have to replace a color that is already assigned with the color you want. You would then use the original name in your write-host.

WARNING: This is untested and may affect the colors on other consoles!

DBADon
  • 449
  • 5
  • 9