Write text in orange with Write-Host
Asked Answered
M

2

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.

Mont answered 28/1, 2015 at 8:21 Comment(2)
Try DarkYellow, however for me this doesn't seem to work...Axes
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.Bautista
J
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.

Jotun answered 19/2, 2022 at 12:3 Comment(0)
C
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!

Cantharides answered 16/4, 2019 at 21:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.