September 19th, 2014

PowerTip: Display Message in 16 Colors

Doctor Scripto
Scripter

Summary: Use Windows PowerShell to display a message in 16 colors.

Hey, Scripting Guy! Question How can I use Windows PowerShell to easily display a message in 16 different colors to start my presentation
           with something a little different?

Hey, Scripting Guy! Answer Use the range operator to create 16 numbers. Pipe the numbers to the Foreach-Object cmdlet. In the
           script block, use Write-Host, and specify the foreground color as the number.
           Here is the command (using aliases for conciseness):

0..15 | %{write-host -f $_ 'hi'}

Author

The "Scripting Guys" is a historical title passed from scripter to scripter. The current revision has morphed into our good friend Doctor Scripto who has been with us since the very beginning.

0 comments

Discussion are closed.