Skip to content

Commit 5f493bb

Browse files
authored
Merge pull request #2 from dbretty/Add-CitrixTemplateRegistry
Added Registry Modules
2 parents 827ae70 + b03187d commit 5f493bb

6 files changed

Lines changed: 412 additions & 4 deletions

File tree

CitrixOptimizerAutomation/CitrixOptimizerAutomation.psd1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
RootModule = 'CitrixOptimizerAutomation.psm1'
1313

1414
# Version number of this module.
15-
ModuleVersion = '2307.002'
15+
ModuleVersion = '2307.003'
1616

1717
# Supported PSEditions
1818
# CompatiblePSEditions = @()
@@ -69,7 +69,7 @@ PowerShellVersion = '5.1'
6969
# NestedModules = @()
7070

7171
# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
72-
FunctionsToExport = @('New-CitrixTemplate', 'New-CitrixTemplateGroup', 'New-CitrixTemplateService', 'New-CitrixTemplateTask')
72+
FunctionsToExport = @('New-CitrixTemplate', 'New-CitrixTemplateGroup', 'New-CitrixTemplateService', 'New-CitrixTemplateTask', 'New-CitrixTemplateRegistry')
7373

7474
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
7575
CmdletsToExport = @()
Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
function New-CitrixTemplateRegistry {
2+
<#
3+
.SYNOPSIS
4+
Creates a new Windows Registry definition in the Citrix Optimizer template.
5+
6+
.DESCRIPTION
7+
This function will create a Registry Definition in the Citrix Optimizer template.
8+
9+
.PARAMETER Path
10+
Specifies the Path to the template file
11+
12+
.PARAMETER GroupName
13+
Specifies the Group in the template file to add the Registry Entry to
14+
15+
.PARAMETER EntryName
16+
The Display Name for the Registry Entry in Citrix Optimizer
17+
18+
.PARAMETER EntryDescription
19+
The Display Description for the Registry Entry in Citrix Optimizer
20+
21+
.PARAMETER ItemName
22+
The Registry Item Name to add
23+
24+
.PARAMETER ItemPath
25+
The Registry Item Path to add
26+
27+
.PARAMETER ItemValue
28+
The Registry Item Value to add
29+
30+
.PARAMETER ItemType
31+
The Registry Item Type to add ("Dword","Binary","ExpandString","MultiString","String","Qword")
32+
33+
.INPUTS
34+
This function will take inputs via pipeline as string
35+
36+
.OUTPUTS
37+
Returns $true or $false depending on the Scheduled Task creation state
38+
39+
.EXAMPLE
40+
PS> New-CitrixTemplateRegistry -Path 'template.xml' -GroupName 'Group1' -EntryName 'Add Edge Update Registry Entry' -EntryDescription 'Disable Edge Updates via HKLM' -ItemName 'UpdatesEnabled' -ItemPath 'HKLM\Software\Microsoft\Edge' -ItemValue '0' -ItemType 'Dword'
41+
Adds an entry to disable the Edge Updates in the template file.
42+
.EXAMPLE
43+
PS> New-CitrixTemplateRegistry -Path $Template.Path -GroupName 'Group1' -EntryName 'Add Edge Update Registry Entry' -EntryDescription 'Disable Edge Updates via HKLM' -ItemName 'UpdatesEnabled' -ItemPath 'HKLM\Software\Microsoft\Edge' -ItemValue '0' -ItemType 'Dword'
44+
Adds an entry to disable the Edge Updates in the template file based on the return value in $Template.Path
45+
.EXAMPLE
46+
PS> New-CitrixTemplateRegistry -Path $Template.Path -GroupName $Group.Name -EntryName 'Add Edge Update Registry Entry' -EntryDescription 'Disable Edge Updates via HKLM' -ItemName 'UpdatesEnabled' -ItemPath 'HKLM\Software\Microsoft\Edge' -ItemValue '0' -ItemType 'Dword'
47+
Adds an entry to disable the Edge Updates in the template file based on the return value in $Template.Path and $Group.Name
48+
.EXAMPLE
49+
PS> New-CitrixTemplateRegistry -Path $Template.Path -GroupName 'System Optimizations' -EntryName 'Remove Edge Item 1' -EntryDescription 'Remove Edge Item 1' -ItemName 'Item1' -ItemPath 'HKLM\Software\Microsoft\Edge' -DeleteValue
50+
Deletes a registry value from the master image
51+
.EXAMPLE
52+
PS> New-CitrixTemplateRegistry -Path $Template.Path -GroupName 'System Optimizations' -EntryName 'Remove Edge Key 1' -EntryDescription 'Remove Edge Key 1' -ItemPath 'HKLM\Software\Microsoft\Edge1' -DeleteKey
53+
Deletes a registry key from the master image
54+
55+
.LINK
56+
https://github.com/dbretty/Citrix.Optimizer.Template/blob/main/Help/New-CitrixTemplateRegistry.MD
57+
#>
58+
59+
[CmdletBinding()]
60+
61+
Param (
62+
[Parameter(
63+
ValuefromPipelineByPropertyName = $true,mandatory=$true
64+
)]
65+
[System.String]$Path,
66+
[Parameter(
67+
ValuefromPipelineByPropertyName = $true,mandatory=$true
68+
)]
69+
[System.String]$GroupName,
70+
[Parameter(
71+
ValuefromPipelineByPropertyName = $true,mandatory=$true
72+
)]
73+
[System.String]$EntryName,
74+
[Parameter(
75+
ValuefromPipelineByPropertyName = $true,mandatory=$true
76+
)]
77+
[System.String]$EntryDescription,
78+
[Parameter(
79+
ValuefromPipelineByPropertyName = $true,mandatory=$false
80+
)]
81+
[System.String]$ItemName,
82+
[Parameter(
83+
ValuefromPipelineByPropertyName = $true,mandatory=$true
84+
)]
85+
[System.String]$ItemPath,
86+
[Parameter(
87+
ValuefromPipelineByPropertyName = $true,mandatory=$false
88+
)]
89+
[System.String]$ItemValue,
90+
[Parameter(
91+
ValuefromPipelineByPropertyName = $true,mandatory=$false
92+
)]
93+
[ValidateSet("Dword","Binary","ExpandString","MultiString","String","Qword")]
94+
[System.String]$ItemType,
95+
[switch]$DeleteValue,
96+
[switch]$DeleteKey
97+
)
98+
99+
begin {
100+
101+
# Set strict mode and initial return value
102+
Set-StrictMode -Version Latest
103+
104+
# Set up PSCustom Object for return
105+
$Return = New-Object -TypeName psobject
106+
$Return | Add-Member -MemberType NoteProperty -Name "Complete" -Value $false
107+
108+
} # begin
109+
110+
process {
111+
112+
if(Get-Template -Path $Path){
113+
114+
write-verbose "Citrix Optimizer Template $($Path) found"
115+
write-verbose "Load Citrix Optimizer Template"
116+
117+
# Load Template and check for existing Group"
118+
[XML]$xmlfile = Get-Content $Path
119+
120+
if(Get-TemplateGroup -Path $Path -GroupName $GroupName){
121+
122+
write-verbose "Group $($GroupName) found"
123+
124+
if(!(Get-TemplateEntry -Path $Path -EntryName $EntryName)){
125+
126+
write-verbose "Registry Entry $($EntryName) not found, adding"
127+
128+
$Group = $xmlfile.root.group | where-object {$_.id -eq $($GroupName)}
129+
130+
write-verbose "Create Entry element"
131+
$Entry = $XMLFile.CreateElement("entry")
132+
133+
write-verbose "Create Name element"
134+
$Name = $XMLFile.CreateElement("name")
135+
$Name.InnerText = $EntryName
136+
$Entry.AppendChild($Name)
137+
138+
$Description = $xmlfile.CreateElement("description")
139+
$Description.InnerText = $EntryDescription
140+
$Entry.AppendChild($Description)
141+
142+
$Execute = $xmlfile.CreateElement("execute")
143+
$Execute.InnerText = "1"
144+
$Entry.AppendChild($Execute)
145+
146+
write-verbose "Create Action element"
147+
$Action = $XMLFile.CreateElement("action")
148+
149+
$Plugin = $XMLFile.CreateElement("plugin")
150+
$Plugin.InnerText = "Registry"
151+
$Action.AppendChild($Plugin)
152+
153+
$Params = $XMLFile.CreateElement("params")
154+
155+
if(!($DeleteKey)){
156+
$ParamName = $XMLFile.CreateElement("name")
157+
$ParamName.InnerText = $ItemName
158+
$Params.AppendChild($ParamName)
159+
}
160+
161+
$ParamPath = $XMLFile.CreateElement("path")
162+
$ParamPath.InnerText = $ItemPath
163+
$Params.AppendChild($ParamPath)
164+
165+
if($DeleteValue){
166+
$ParamValue = $XMLFile.CreateElement("value")
167+
$ParamValue.InnerText = "CTXOE_DeleteValue"
168+
$Params.AppendChild($ParamValue)
169+
} else {
170+
if($DeleteKey){
171+
$ParamValue = $XMLFile.CreateElement("value")
172+
$ParamValue.InnerText = "CTXOE_DeleteKey"
173+
$Params.AppendChild($ParamValue)
174+
} else {
175+
$ParamValue = $XMLFile.CreateElement("value")
176+
$ParamValue.InnerText = $ItemValue
177+
$Params.AppendChild($ParamValue)
178+
}
179+
}
180+
181+
if((!($DeleteValue)) -and (!($DeleteKey))){
182+
$ParamValueType = $XMLFile.CreateElement("valuetype")
183+
$ParamValueType.InnerText = $ItemType
184+
$Params.AppendChild($ParamValueType)
185+
}
186+
187+
$Action.AppendChild($Params)
188+
189+
$Entry.AppendChild($Action)
190+
191+
$Group.AppendChild($Entry)
192+
193+
$XMLFile.Save($Path)
194+
write-verbose "Registry Entry $($EntryName) added"
195+
$Return.Complete = $true
196+
197+
} else {
198+
199+
write-verbose "Entry $($EntryName) already found - quitting"
200+
write-error "Entry $($EntryName) already found - quitting"
201+
202+
}
203+
204+
} else {
205+
206+
write-verbose "Group $($GroupName) not found - quitting"
207+
write-error "Group $($GroupName) not found - quitting"
208+
209+
}
210+
} else {
211+
212+
write-verbose "Template $($Path) not found - quitting"
213+
write-error "Template $($Path) not found - quitting"
214+
215+
}
216+
217+
} # process
218+
219+
end {
220+
221+
return $Return
222+
223+
} # end
224+
225+
}

CitrixOptimizerAutomation/Public/New-CitrixTemplateTask.ps1

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,10 @@ process {
107107

108108
# Decode Task Path
109109
$Task = Get-TaskDetail -TaskPath $TaskPath
110+
write-verbose "Create Entry element"
110111
$Entry = $XMLFile.CreateElement("entry")
111112

113+
write-verbose "Create Name element"
112114
$Name = $XMLFile.CreateElement("name")
113115
$Name.InnerText = $TaskName
114116
$Entry.AppendChild($Name)
@@ -121,6 +123,7 @@ process {
121123
$Execute.InnerText = "1"
122124
$Entry.AppendChild($Execute)
123125

126+
write-verbose "Create Action element"
124127
$Action = $XMLFile.CreateElement("action")
125128

126129
$Plugin = $XMLFile.CreateElement("plugin")
@@ -153,8 +156,8 @@ process {
153156

154157
} else {
155158

156-
write-verbose "Entry $($EntryName) already found - quitting"
157-
write-error "Entry $($EntryName) already found - quitting"
159+
write-verbose "Entry $($TaskName) already found - quitting"
160+
write-error "Entry $($TaskName) already found - quitting"
158161

159162
}
160163

Examples/TestScript.ps1

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,18 @@ New-CitrixTemplateTask -Path $Template.Path -GroupName 'System Optimizations' -T
2727
New-CitrixTemplateTask -Path $Template.Path -GroupName 'System Optimizations' -TaskName 'SchTask - OfficeUpdate' -TaskPath '\Microsoft\Windows\Office\Update\' -TaskDescription 'This is the Office Update Scheduled Task' -State "Disabled"
2828
New-CitrixTemplateTask -Path $Template.Path -GroupName 'System Optimizations' -TaskName 'SchTask - Microsoft Edge Update' -TaskPath '\Microsoft\Edge\Update\' -TaskDescription 'This is the Microsoft Edge Update Scheduled Task' -State "Disabled"
2929

30+
# Create Registry Values
31+
New-CitrixTemplateRegistry -Path $Template.Path -GroupName 'System Optimizations' -EntryName 'Add Edge Update Registry Entry' -EntryDescription 'Disable Edge Updates via HKLM' -ItemName 'UpdatesEnabled' -ItemPath 'HKLM\Software\Microsoft\Edge' -ItemValue '0' -ItemType 'Dword'
32+
New-CitrixTemplateRegistry -Path $Template.Path -GroupName 'System Optimizations' -EntryName 'Add Edge Sandbox' -EntryDescription 'Enable Edge Sandbox' -ItemName 'Sandbox' -ItemPath 'HKLM\Software\Microsoft\Edge' -ItemValue 'Enabled' -ItemType 'String'
33+
New-CitrixTemplateRegistry -Path $Template.Path -GroupName 'System Optimizations' -EntryName 'Add Edge Extensions' -EntryDescription 'Disable Edge Extensions' -ItemName 'ExtensionsDisabled' -ItemPath 'HKLM\Software\Microsoft\Edge' -ItemValue '1' -ItemType 'Dword'
34+
35+
# Remove Registry Values
36+
New-CitrixTemplateRegistry -Path $Template.Path -GroupName 'System Optimizations' -EntryName 'Remove Edge Item 1' -EntryDescription 'Remove Edge Item 1' -ItemName 'Item1' -ItemPath 'HKLM\Software\Microsoft\Edge' -DeleteValue
37+
New-CitrixTemplateRegistry -Path $Template.Path -GroupName 'System Optimizations' -EntryName 'Remove Edge Item 2' -EntryDescription 'Remove Edge Item 2' -ItemName 'Item2' -ItemPath 'HKLM\Software\Microsoft\Edge' -DeleteValue
38+
New-CitrixTemplateRegistry -Path $Template.Path -GroupName 'System Optimizations' -EntryName 'Remove Edge Item 3' -EntryDescription 'Remove Edge Item 3' -ItemName 'Item3' -ItemPath 'HKLM\Software\Microsoft\Edge' -DeleteValue
39+
40+
# Remove Registry Keys
41+
New-CitrixTemplateRegistry -Path $Template.Path -GroupName 'System Optimizations' -EntryName 'Remove Edge Key 1' -EntryDescription 'Remove Edge Key 1' -ItemPath 'HKLM\Software\Microsoft\Edge1' -DeleteKey
42+
New-CitrixTemplateRegistry -Path $Template.Path -GroupName 'System Optimizations' -EntryName 'Remove Edge Key 2' -EntryDescription 'Remove Edge Key 2' -ItemPath 'HKLM\Software\Microsoft\Edge2' -DeleteKey
43+
New-CitrixTemplateRegistry -Path $Template.Path -GroupName 'System Optimizations' -EntryName 'Remove Edge Key 3' -EntryDescription 'Remove Edge Key 3' -ItemPath 'HKLM\Software\Microsoft\Edge3' -DeleteKey
44+

0 commit comments

Comments
 (0)