Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 450
Jérôme Avatar asked Jan 28 '15 08:01

Jérôme


People also ask

Where does write-host write to?

Write-Host sends the objects to the host. It does not return any objects. However, the host displays the objects that Write-Host sends to it.

What is write-host?

The PowerShell Write-Host cmdlet is used to write the customized output to a host. We can specify the text color by using the -foreground parameter, and by using the -background parameter, we can specify the background color.


1 Answers

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.

like image 71
Darin Avatar answered Nov 10 '22 05:11

Darin