'Write text in orange with Write-Host
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.
Solution 1:[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:
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.
Solution 2:[2]
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!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Darin |
| Solution 2 | DBADon |

