|
| 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 | +} |
0 commit comments