Public/Import/Import-ISEThemeFile.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
function Import-ISEThemeFile {

    [cmdletbinding()]
    Param(
        [Parameter(Mandatory=$True,ValueFromPipeline=$True,ValueFromPipelinebyPropertyName=$True)]
        [object]$FileName,

        [Parameter()]
        [switch]$ApplyTheme
    )

    Begin{}

    Process {
        # Get fullname if gci object passed
        If ($FileName.FullName) {
            [string]$FileName = $FileName.FullName
        }

        #-Create xml variable from file name
        [xml]$xml = get-content $FileName
        #Create xml string variable from file name
        [string]$xmlString = get-content $FileName

        #-Get theme name for registry value name
        $ThemeName = $xml.StorableColorTheme.Name

        #-Set value data to the xml string
        Set-ItemProperty HKCU:\Software\Microsoft\PowerShell\3\Hosts\PowerShellISE\ColorThemes -Name $ThemeName -Value $xmlString -Type String -Force

        #-Apply theme to current session if called
        If ($ApplyTheme) {
            Set-ISETheme -ThemeName $ThemeName
        }
    }

    End{}
    <#
     .SYNOPSIS
      Imports an ISE theme xml file into the registry
 
  .DESCRIPTION
   Imports an ISE theme xml file into the registry and applies it
            to the current session if ApplyTheme is passed
 
  .PARAMETER File
   An ISE theme xml filename
 
   .PARAMETER ApplyTheme
   Switch for applying the theme after importing it.
 
        .EXAMPLE
   PS C:\> Import-ISEThemeFile "C:\ISEthemes\.StorableColorTheme.ps1xml"
 
            Imports ISE theme to the registry
 
        .EXAMPLE
   PS C:\> Get-FileName | Import-ISEThemeFile -ApplyTheme
 
            Imports piped in ISE theme to the registry and applies the theme to the current session
 
  .NOTES
            Part of the ISEColorThemeCmdlets.ps1 Script by Jeff Pollock
            http://Lifeinpowerhsell.blogspot.com
            http://gallery.technet.microsoft.com/ISE-Color-Theme-Cmdlets-24905f9e
 #>


}