1
+ Import-LocalizedData - BindingVariable localizedData - FileName Resources.psd1
2
+
3
+ function Get-TargetResource {
4
+ [CmdletBinding ()]
5
+ [OutputType ([System.Collections.Hashtable ])]
6
+ param (
7
+ [Parameter (Mandatory )] [ValidateSet (' Controller' , ' Studio' , ' Storefront' , ' Licensing' , ' Director' , ' DesktopVDA' , ' SessionVDA' )] [System.String ] $Role , # Studio?
8
+ [Parameter (Mandatory )] [ValidateNotNullOrEmpty ()] [System.String ] $SourcePath ,
9
+ [Parameter ()] [AllowNull ()] [System.Management.Automation.PSCredential ] $Credential ,
10
+ [Parameter ()] [ValidateNotNullOrEmpty ()] [ValidateSet (' Present' , ' Absent' )] $Ensure = ' Present'
11
+ )
12
+ process {
13
+ $targetResource = @ {
14
+ Role = $Role ;
15
+ SourcePath = $SourcePath ;
16
+ Credential = $Credential ;
17
+ Ensure = ' Absent' ;
18
+ }
19
+ if (GetXDInstalledProduct - Role $Role ) {
20
+ $targetResource [' Ensure' ] = ' Present' ;
21
+ }
22
+ return $targetResource ;
23
+ } # end process
24
+ } # end function Get-TargetResource
25
+
26
+ function Test-TargetResource {
27
+ [CmdletBinding ()]
28
+ [OutputType ([System.Boolean ])]
29
+ param (
30
+ [Parameter (Mandatory )] [ValidateSet (' Controller' , ' Studio' , ' Storefront' , ' Licensing' , ' Director' , ' DesktopVDA' , ' SessionVDA' )] [System.String ] $Role ,
31
+ [Parameter (Mandatory )] [ValidateNotNullOrEmpty ()] [System.String ] $SourcePath ,
32
+ [Parameter ()] [AllowNull ()] [System.Management.Automation.PSCredential ] $Credential ,
33
+ [Parameter ()] [ValidateNotNullOrEmpty ()] [ValidateSet (' Present' , ' Absent' )] $Ensure = ' Present'
34
+ )
35
+ process {
36
+ $targetResource = Get-TargetResource @PSBoundParameters ;
37
+ if ($Ensure -eq $targetResource.Ensure ) { return $true ; }
38
+ else { return $false ; }
39
+ } # end process
40
+ } # end function Test-TargetResource
41
+
42
+ function Set-TargetResource {
43
+ [CmdletBinding ()]
44
+ param (
45
+ [Parameter (Mandatory )] [ValidateSet (' Controller' , ' Studio' , ' Storefront' , ' Licensing' , ' Director' , ' DesktopVDA' , ' SessionVDA' )] [System.String ] $Role ,
46
+ [Parameter (Mandatory )] [ValidateNotNullOrEmpty ()] [System.String ] $SourcePath ,
47
+ [Parameter ()] [AllowNull ()] [System.Management.Automation.PSCredential ] $Credential ,
48
+ [Parameter ()] [ValidateNotNullOrEmpty ()] [ValidateSet (' Present' , ' Absent' )] $Ensure = ' Present' ,
49
+ [Parameter ()] [ValidateNotNullOrEmpty ()] [System.String ] $LogPath = (Join-Path - Path $env: TMP - ChildPath ' \Citrix\XenDesktop Installer' )
50
+ )
51
+ begin {
52
+ if (-not (Test-Path - Path $SourcePath - PathType Container)) {
53
+ throw ($localizedData.InvalidSourcePathError -f $SourcePath );
54
+ }
55
+ }
56
+ process {
57
+ Write-Verbose ($localizedData.LogDirectorySet -f $logPath );
58
+ Write-Verbose ($localizedData.SourceDirectorySet -f $SourcePath );
59
+ $installMediaPath = ResolveXDSetupMedia - Role $Role - SourcePath $SourcePath ;
60
+ if ($Ensure -eq ' Present' ) {
61
+ Write-Verbose ($localizedData.InstallingRole -f $Role );
62
+ $installArguments = ResolveXDSetupArguments - Role $Role - LogPath $LogPath ;
63
+ }
64
+ else {
65
+ # # Uninstall
66
+ Write-Verbose ($localizedData.UninstallingRole -f $Role );
67
+ $installArguments = ResolveXDSetupArguments - Role $Role - LogPath $LogPath - Uninstall;
68
+ }
69
+ $exitCode = StartWaitProcess - FilePath $installMediaPath - ArgumentList $installarguments - Credential $Credential ;
70
+ # Check for reboot
71
+ if ($exitCode -eq 3010 ) {
72
+ $global :DSCMachineStatus = 1 ;
73
+ }
74
+ } # end process
75
+ } # end function Set-TargetResource
76
+
77
+ # region Private Functions
78
+
79
+ function GetXDInstalledProduct {
80
+ <#
81
+ . SYNOPSIS
82
+ Returns installed XD product by role.
83
+ #>
84
+ [CmdletBinding ()]
85
+ [OutputType ([Microsoft.Win32.RegistryKey ])]
86
+ param (
87
+ # # Citrix XenDesktop 7.x role to install/uninstall.
88
+ [Parameter (Mandatory )] [ValidateSet (' Controller' , ' Studio' , ' Storefront' , ' Licensing' , ' Director' , ' DesktopVDA' , ' SessionVDA' )] [System.String ] $Role
89
+ )
90
+ process {
91
+ switch ($Role ) {
92
+ ' Controller' { $wmiFilter = ' Citrix Broker Service' ; }
93
+ ' Studio' { $wmiFilter = ' Citrix Studio' ; }
94
+ ' Storefront' { $wmiFilter = ' Citrix Storefront' ; }
95
+ ' Licensing' { $wmiFilter = ' Citrix Licensing' ; }
96
+ ' Director' { $wmiFilter = ' Citrix Director' ; }
97
+ ' DesktopVDA' { $wmiFilter = ' Citrix Virtual Desktop Agent' ; }
98
+ ' SessionVDA' { $wmiFilter = ' Citrix Virtual Desktop Agent' ; } # Name: Citrix Virtual Delivery Agent 7.6, DisplayName: Citrix Virtual Desktop Agent?
99
+ }
100
+ return Get-WmiObject - Class ' Win32_Product' - Filter " Name Like '%$wmiFilter %'" ;
101
+ } # end process
102
+ } # end functoin GetXDInstalledProduct
103
+
104
+ function ResolveXDSetupMedia {
105
+ <#
106
+ . SYNOPSIS
107
+ Resolve the correct installation media source for the
108
+ local architecture depending on the role.
109
+ #>
110
+ [CmdletBinding ()]
111
+ [OutputType ([System.String ])]
112
+ param (
113
+ # # Citrix XenDesktop 7.x role to install/uninstall.
114
+ [Parameter (Mandatory )] [ValidateSet (' Controller' , ' Studio' , ' Storefront' , ' Licensing' , ' Director' , ' DesktopVDA' , ' SessionVDA' )] [System.String ] $Role ,
115
+ # # Citrix XenDesktop 7.x installation media path.
116
+ [Parameter (Mandatory )] [ValidateNotNullOrEmpty ()] [System.String ] $SourcePath
117
+ )
118
+ process {
119
+ $architecture = ' x86' ;
120
+ if ([System.Environment ]::Is64BitOperatingSystem) {
121
+ $architecture = ' x64' ;
122
+ }
123
+ switch ($Role ) {
124
+ ' DesktopVDA' { $installMedia = ' XenDesktopVdaSetup.exe' ; }
125
+ ' SessionVDA' { $installMedia = ' XenDesktopVdaSetup.exe' ; }
126
+ Default { $installMedia = ' XenDesktopServerSetup.exe' ; }
127
+ }
128
+ $sourceArchitecturePath = Join-Path - Path $SourcePath - ChildPath $architecture ;
129
+ $installMediaPath = Get-ChildItem - Path $sourceArchitecturePath - Filter $installMedia - Recurse - File;
130
+ if (-not $installMediaPath ) {
131
+ throw ($localizedData.NoValidSetupMediaError -f $installMedia , $sourceArchitecturePath );
132
+ }
133
+ return $installMediaPath.FullName ;
134
+ } # end process
135
+ } # end function ResolveXDSetupMedia
136
+
137
+ function ResolveXDSetupArguments {
138
+ <#
139
+ . SYNOPSIS
140
+ Resolve the installation arguments for the associated
141
+ XenDesktop role.
142
+ #>
143
+ [CmdletBinding ()]
144
+ [OutputType ([System.String ])]
145
+ param (
146
+ # # Citrix XenDesktop 7.x role to install/uninstall.
147
+ [Parameter (Mandatory )] [ValidateSet (' Controller' , ' Studio' , ' Storefront' , ' Licensing' , ' Director' , ' DesktopVDA' , ' SessionVDA' )] [System.String ] $Role ,
148
+ # # Citrix XenDesktop 7.x installation media path.
149
+ [Parameter ()] [ValidateNotNullOrEmpty ()] [System.String ] $LogPath = (Join-Path - Path $env: TMP - ChildPath ' \Citrix\XenDesktop Installer' ),
150
+ # # Uninstall Citrix XenDesktop 7.x product.
151
+ [Parameter ()] [System.Management.Automation.SwitchParameter ] $Uninstall
152
+ )
153
+ process {
154
+ $arguments = New-Object - TypeName System.Collections.ArrayList - ArgumentList @ ();
155
+ $arguments.AddRange (@ (' /QUIET' , ' /LOGPATH' , " `" $LogPath `" " , ' /NOREBOOT' , ' /COMPONENTS' ));
156
+ switch ($Role ) {
157
+ # # Install/uninstall component names by role
158
+ ' Controller' { [ref ] $null = $arguments.Add (' CONTROLLER' ); }
159
+ ' Studio' { [ref ] $null = $arguments.Add (' DESKTOPSTUDIO' ); }
160
+ ' Storefront' { [ref ] $null = $arguments.Add (' STOREFRONT' ); }
161
+ ' Licensing' { [ref ] $null = $arguments.Add (' LICENSESERVER' ); }
162
+ ' Director' { [ref ] $null = $arguments.Add (' DESKTOPDIRECTOR' ); }
163
+ { @ (' SessionVDA' , ' DesktopVDA' ) -contains $_ } { $arguments.AddRange (@ (' VDA,PLUGINS' )); }
164
+ } # end switch Role
165
+
166
+ if ($Uninstall ) {
167
+ [ref ] $null = $arguments.Add (' /REMOVE' );
168
+ }
169
+ else {
170
+ # # Additional install parameters per role
171
+ switch ($Role ) {
172
+ ' Controller' { $arguments.AddRange (@ (' /CONFIGURE_FIREWALL' , ' /NOSQL' )); }
173
+ ' Studio' { $arguments.AddRange (@ (' /CONFIGURE_FIREWALL' )); }
174
+ ' Storefront' { $arguments.AddRange (@ (' /CONFIGURE_FIREWALL' )); }
175
+ ' Licensing' { $arguments.AddRange (@ (' /CONFIGURE_FIREWALL' )); }
176
+ ' Director' { };
177
+ { @ (' SessionVDA' , ' DesktopVDA' ) -contains $_ } {
178
+ $arguments.AddRange (@ (' /OPTIMIZE' , ' /ENABLE_HDX_PORTS' , ' /ENABLE_REAL_TIME_TRANSPORT' , ' /ENABLE_REMOTE_ASSISTANCE' ));
179
+ }
180
+ ' DesktopVDA' {
181
+ if ((Get-WmiObject - ClassName ' Win32_OperatingSystem' ).Caption -match ' Server' ) {
182
+ [ref ] $null = $arguments.Add (' /SERVERVDI' );
183
+ }
184
+ }
185
+ } # end switch Role
186
+ }
187
+ return [System.String ]::Join(' ' , $arguments.ToArray ());
188
+ } # end process
189
+ } # end function ResolveXDSetupArguments
190
+
191
+ function StartWaitProcess {
192
+ <#
193
+ . SYNOPSIS
194
+ Starts and waits for a process to exit.
195
+ . NOTES
196
+ This is an internal function and shouldn't be called from outside.
197
+ #>
198
+ [CmdletBinding (SupportsShouldProcess )]
199
+ [OutputType ([System.Int32 ])]
200
+ param (
201
+ # Path to process to start.
202
+ [Parameter (Mandatory )] [ValidateNotNullOrEmpty ()] [System.String ] $FilePath ,
203
+ # Arguments (if any) to apply to the process.
204
+ [Parameter ()] [AllowNull ()] [System.String []] $ArgumentList ,
205
+ # Credential to start the process as.
206
+ [Parameter ()] [AllowNull ()] [System.Management.Automation.PSCredential ] $Credential ,
207
+ # Working directory
208
+ [Parameter ()] [ValidateNotNullOrEmpty ()] [System.String ] $WorkingDirectory = (Split-Path - Path $FilePath - Parent)
209
+ )
210
+ process {
211
+ $startProcessParams = @ {
212
+ FilePath = $FilePath ;
213
+ WorkingDirectory = $WorkingDirectory ;
214
+ NoNewWindow = $true ;
215
+ PassThru = $true ;
216
+ };
217
+ $displayParams = ' <None>' ;
218
+ if ($ArgumentList ) {
219
+ $displayParams = [System.String ]::Join(' ' , $ArgumentList );
220
+ $startProcessParams [' ArgumentList' ] = $ArgumentList ;
221
+ }
222
+ Write-Verbose ($localizedData.StartingProcess -f $FilePath , $displayParams );
223
+ if ($Credential ) {
224
+ Write-Verbose ($localizedData.StartingProcessAs -f $Credential.UserName );
225
+ $startProcessParams [' Credential' ] = $Credential ;
226
+ }
227
+ if ($PSCmdlet.ShouldProcess ($FilePath , ' Start Process' )) {
228
+ $process = Start-Process @startProcessParams - ErrorAction Stop;
229
+ }
230
+ if ($PSCmdlet.ShouldProcess ($FilePath , ' Wait Process' )) {
231
+ Write-Verbose ($localizedData.ProcessLaunched -f $process.Id );
232
+ Write-Verbose ($localizedData.WaitingForProcessToExit -f $process.Id );
233
+ $process.WaitForExit ();
234
+ $exitCode = [System.Convert ]::ToInt32($process.ExitCode );
235
+ Write-Verbose ($localizedData.ProcessExited -f $process.Id , $exitCode );
236
+ }
237
+ return $exitCode ;
238
+ } # end process
239
+ } # end function StartWaitProcess
240
+
241
+ # endregion Private Functions
0 commit comments