How do I use a rgb(116, 0, 110) in code for Powershell console.BackgroundColor? RRS feed

  • Question

  • I can use PowerShell Property dialog to select a red green blue BackgroundColor but in code I only have [System.ConsoleColor]::

    • Black
    • Blue
    • Cyan
    • DarkBlue
    • DarkCyan
    • DarkGray
    • DarkGreen
    • DarkMagenta
    • DarkRed
    • DarkYellow
    • Gray
    • Green
    • Magenta
    • Red
    • White
    • Yellow

    I want like a .NET [System.Drawing.Color]::MediumPurple


    rgb(116, 0, 110)

    David Morrow

    Wednesday, June 8, 2016 10:49 PM


All replies

  • Console colors are limited.  They are ordinals 0-15.


    That's all that we support.


    Thursday, June 9, 2016 1:23 AM
  • I want like a .NET [System.Drawing.Color]::MediumPurple

    Unfortunately, wishful thinking does not cause features to spring into existence.

    -- Bill Stewart [Bill_Stewart]

    Thursday, June 9, 2016 1:11 PM
  • But have you tried right clicking top of PowerShell window and select Properties then click Color. You can see that selecting a red, green, blue color is possible.

    David Morrow

    Thursday, June 9, 2016 8:12 PM
  • I tried DarkMagenta its the color I want, but I program with C# so thats my interest.

    David Morrow

    Thursday, June 9, 2016 8:25 PM
  • It looks like setting custom colors in that way is not available through the standard .NET console APIs. It is possible you could do this using unmanaged code, but this isn't trivial and requires a good understanding of how to invoke Win32 API calls from .NET (and this is not the right forum to ask about that).

    Also, this is not a C# programming forum but rather a scripting forum.

    -- Bill Stewart [Bill_Stewart]

    Thursday, June 9, 2016 8:31 PM