I had a need to display multiple colors on a single line. Since Write-Host only supports a single ForegroundColor — I wrote this.
Code: http://pastebin.com/GiWpLMAA
The system uses Color Codes in a string to determine the color. The color codes are in the format of c + the code of the color you want to display.
######################################### # Write-Color Color Codes ######################################### # ^cn = Normal Output Color # ^ck = Black # ^cb = Blue # ^cc = Cyan # ^ce = Grey # ^cg = Green # ^cm = Magenta # ^cr = Red # ^cw = White # ^cy = Yellow # ^cB = DarkBlue # ^cC = DarkCyan # ^cE = DarkGrey # ^cG = DarkGreen # ^cM = DarkMagenta # ^cR = DarkRed # ^cY = DarkYellow [Unsupported in Powershell] #########################################
For example if I wanted Happy to bed Red and Birthday to be green
Write-Color "Hey! ^crHappy ^cgBirthday^cn, You!"
Happy would be red, Birthday would be green, and the rest would be normal color.
submitted by /u/Kewlb
[link] [comments]
The post Write-Color – Multiple colors on a single line! appeared first on How to Code .NET.