Description

This script contains a worker function that displays the windows.forms colordialog dialog box and returns the RGB colour values. You can select a colour using the dialog, and click OK. The script then displays the RGB values you selected

Script

PowerShell
Edit|Remove
<#
.SYNOPSIS
This script displays the Windows Color dialog box, then
displays the r, g, b values of the colours selected
.DESCRIPTION
This script calls windows.forms to show the color dialog. You then
select a colour, and hit OK. The script then displays the values you selected.
.NOTES
File Name : Get-ColourRGB.ps1
Author : Thomas Lee - tfl@psp.co.uk
Requires : PowerShell Version 2.0
.LINK
This script posted to:
http://pshscripts.blogspot.com/2010/09/get-colourrgbps1.html
#>

# Define worker function
function Get-ColourRGB {
param(
$R = 0, # Red value
$G = 0, # Green value
$B = 0 # Blue value
)

# Load assemblies just in case

[void][reflecti
on.assembly]::LoadWithPartialName("System.Drawing")
  [void][reflection.assembly]::LoadWithPartialName("system.Windows.Forms")

# Show colour dialog, get colour
$colorDialog = New-Object Windows.Forms.ColorDialog -Property @{
FullOpen = $true
Color = [Drawing.Color]::FromArgb($R,$G,$B)
}

if ($colorDialog.ShowDialog() -eq "OK") {
$R = $colordialog.color.R
$G = $colordialog.color.G
$B = $colordialog.color.B
$R;$G;$B
}
}

# Call the worker function
$R1,$G1,$B1 = Get-ColourRGB 128 128 128

# Describe
" You set:"
" R to: {0}" -f $R1
" G to: {0}" -f $G1
" B to: {0}" -f $B1