PowerTip: Display Message in 16 Colors


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'}

Comments (7)

  1. Dan Leander says:

    $text = "Hello World!"

    0..($text.length – 1)| % {
    $color = Get-Random -Minimum 0 -Maximum 15
    Write-Host -f $color $text[$_] -NoNewline
    }

  2. jra says:

    Cool

    #Dan good example

  3. JV says:

    OK – now I get comments in the RSS feed marks with the date "tomorrow" How cab I get tomorrows RSS comments? I can send a screenshot.

Skip to main content