Translate Color Name to ARGB Using PowerShell

ARGB stands for Alpha Red Green Blue and is something I use quite often when I work with a WPF and want to get a color for font or something else. Basically, if you want a color like Green, sometimes you have to use the ARGB type, which is #FF008000. Figuring out what this is can be annoying unless you have web access. Fortunately,  I wrote a simple function that can do this for me with little effort. While not everyone will find this useful, I figured I would post the code here along with some examples.

Function Get-ARGBColor {
    Param ([string[]]$Color)
    Begin {
        Add-Type –assemblyName PresentationFramework
    }
    Process {
        If (-Not $PSBoundParameters['Color']) {
            $Color = [windows.media.colors] | Get-Member -static -Type Property | Select -Expand Name        
        }
        ForEach ($c in $color) {
            Try {
                $ARGB = [windows.media.color]$c
                New-Object PSObject -Property @{
                    ARGB = "$([windows.media.colors]::$c)"
                    Color = $c
                }
            } Catch {
                Write-Warning "$c is not a valid color"
            }
        }
    }
}
Get-ARGBColor -Color Green

image

Get-ARGBColor -Color Red,Yellow,Blue

image

If you just want to list out all available pre-defined colors, just run the command without any parameters.

image

image

About Boe Prox

Microsoft Cloud and Datacenter MVP working as a SQL DBA.
This entry was posted in powershell and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s