Public/Convert/Convert-ARGBToHex.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
function Convert-ARGBToHex {

    [cmdletbinding()]
    Param(
        [parameter(Mandatory=$True)]
        [string]$RGB_Val
    )
    
    Begin{}

    Process {
        #-separate the ARGB values
        $var_RGB = $RGB_Val.split(',')

        #-Convert values to Hex
        $var_A = [Convert]::ToString($var_RGB[0], 16).ToUpper()
        $var_R = [Convert]::ToString($var_RGB[1], 16).ToUpper()
        $var_G = [Convert]::ToString($var_RGB[2], 16).ToUpper()
        $var_B = [Convert]::ToString($var_RGB[3], 16).ToUpper()

        #-pad single digit values to ensure 8 character Hex is returned
        If ($var_A.Length -eq 1) {$var_A = "0$var_A"}
        If ($var_R.Length -eq 1) {$var_R = "0$var_R"}
        If ($var_G.Length -eq 1) {$var_G = "0$var_G"}
        If ($var_B.Length -eq 1) {$var_B = "0$var_B"}

        #-Output concatenated hex value
        Write-Output "#$var_A$var_R$var_G$var_B"
    }

    End{}
    <#
     .SYNOPSIS
      Converts ARGB to Hex values
 
  .DESCRIPTION
   Converts ARGB to Hex values. ARGB values are needed to save console colors to xml format
 
  .PARAMETER Hex_Val
   The ARGB value
 
        .EXAMPLE
   PS C:\> $Hex = Convert-ARGBToHex $ARGBValue
 
            Assigns converted ARGB value to Hex variable
 
  .NOTES
            Part of the ISEColorThemeCmdlets.ps1 Script by Jeff Pollock
            http://Lifeinpowerhsell.blogspot.com
            http://gallery.technet.microsoft.com/ISE-Color-Theme-Cmdlets-24905f9e
 #>


}