Public/Get/Get-ISETheme.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
function Get-ISETheme {

    [cmdletbinding()]
    Param(
        [Parameter(Mandatory=$True,ParameterSetName='fromfile',ValueFromPipeline=$True,ValueFromPipelinebyPropertyName=$True)]
        [string]$File,

        [Parameter(Mandatory=$True,ParameterSetName='fromreg',ValueFromPipeline=$True,ValueFromPipelinebyPropertyName=$True)]
        [string]$ThemeName
    )

    Begin{}

    Process {
        #-Determine proper xml assignment according to whether an xml file was passed or a registry Theme
        If ($File) {        
            [xml]$xml = get-content $File
        } Else {
            $Theme = Get-ItemProperty HKCU:\Software\Microsoft\PowerShell\3\Hosts\PowerShellISE\ColorThemes -Name $ThemeName
            $Theme | ForEach-Object {
                $xml = $_.$ThemeName
            }
        }

        #-Create xml object array to store xml values from the Theme
        $xmlObjects = @()

        $x = 0
        $xml.StorableColorTheme.Keys.String | ForEach-Object {
            #-Set class according to presence of a "\" in the attribute name
            If ($_.Contains('\')) {
                $Class = $_.Substring(0,$_.IndexOf('\'))
                $Attribute = $_.Substring($_.IndexOf('\') + 1)
            } Else {
                $Class = 'Base'
                $Attribute = $_
            }
            
            #-Get the ARGB values from the xml
            $var_A = $xml.StorableColorTheme.Values.Color[$x].A
            $var_R = $xml.StorableColorTheme.Values.Color[$x].R
            $var_G = $xml.StorableColorTheme.Values.Color[$x].G
            $var_B = $xml.StorableColorTheme.Values.Color[$x].B

            #-Convert ARGB values to Hex
            $Hex = Convert-ARGBToHex "$var_A,$var_R,$var_G,$var_B"
            
            #-Create new xml object and add it the the xml object array
            $xmlObj = New-Object -Type PSObject
            $xmlObj | Add-Member -MemberType NoteProperty -Name Class –Value $Class
            $xmlObj | Add-Member -MemberType NoteProperty -Name Attribute –Value $Attribute
            $xmlObj | Add-Member -MemberType NoteProperty -Name A –Value $var_A
            $xmlObj | Add-Member -MemberType NoteProperty -Name R –Value $var_R
            $xmlObj | Add-Member -MemberType NoteProperty -Name G –Value $var_G
            $xmlObj | Add-Member -MemberType NoteProperty -Name B –Value $var_B
            $xmlObj | Add-Member -MemberType NoteProperty -Name Hex –Value $Hex
            $xmlObjects += $xmlObj        
            $x = $x + 1        
        }

        #-Get Font
        $xmlObj = New-Object -Type PSObject
        $xmlObj | Add-Member -MemberType NoteProperty -Name Class –Value 'Other'
        $xmlObj | Add-Member -MemberType NoteProperty -Name Name –Value $xml.StorableColorTheme.Name
        $xmlObj | Add-Member -MemberType NoteProperty -Name FontFamily –Value $xml.StorableColorTheme.FontFamily
        $xmlObj | Add-Member -MemberType NoteProperty -Name FontSize –Value $xml.StorableColorTheme.FontSize
        $xmlObjects += $xmlObj

        #-Return xml object array
        $xmlObjects       
    }

    End{}
    <#
     .SYNOPSIS
      Gets an ISE theme
 
  .DESCRIPTION
   Gets an ISE them from either the registry or xml file
 
  .PARAMETER File
   An ISE theme xml filename
 
   .PARAMETER ThemeName
   The name of an ISE theme stored in the registry
 
        .EXAMPLE
   PS C:\> $Theme = Get-FileName | Get-ISETheme
 
            Gets the ISE theme information from the supplied xml file and assigns it to Theme
 
  .NOTES
            Part of the ISEColorThemeCmdlets.ps1 Script by Jeff Pollock
            http://Lifeinpowerhsell.blogspot.com
            http://gallery.technet.microsoft.com/ISE-Color-Theme-Cmdlets-24905f9e
 #>


}