Skip to content

Commit 6b8f816

Browse files
committed
Initial commit
0 parents  commit 6b8f816

16 files changed

+800
-0
lines changed

.gitattributes

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto
3+
*.ps1 -text
4+
*.psm1 -text
5+
*.psd1 -text
6+
*.mof -text
7+
*.md -text
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<#
2+
function Add-Admins {
3+
param (
4+
# Framework version to check against.
5+
[Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [string] $Administratorsgroup
6+
7+
)
8+
9+
process {
10+
11+
Write-Verbose ('Adding Full Administrator Role for ' + $Administratorsgroup);
12+
New-AdminAdministrator -AdminAddress $env:COMPUTERNAME -Enabled $True -Name $Administratorsgroup | Out-Null
13+
Add-AdminRight -AdminAddress $env:COMPUTERNAME -Administrator $Administratorsgroup -Role 'Full Administrator' -Scope 'All'
14+
15+
}
16+
}
17+
#>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
��
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<#
2+
function Create-DB {
3+
[CmdletBinding()]
4+
param (
5+
#[Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [String] $DBUSER,
6+
#[Parameter(Mandatory)] [ValidateNotNullOrEmpty()] $DBPWD,
7+
[Parameter(Mandatory)] [ValidateNotNullOrEmpty()] $Database_CredObject,
8+
[Parameter()] [ValidateNotNullOrEmpty()] [String] $DBSERVER
9+
10+
)
11+
12+
process {
13+
14+
#$DBPWD = $DBPWD | ConvertTo-SecureString -asPlainText -Force
15+
#$Database_CredObject = New-Object System.Management.Automation.PSCredential($DBUSER,$DBPWD)
16+
17+
Write-Verbose ('Starting DB Creation at ' + (get-date).ToLongTimeString());
18+
$Sresult = New-XDDatabase -AdminAddress $env:COMPUTERNAME -SiteName $defaults.SITENAME -DataStore Site -DatabaseServer $DBSERVER -DatabaseName $defaults.DBSITENAME -DatabaseCredentials $Database_CredObject
19+
Write-Verbose ('Created Site DB ' + $Sresult.Name + ' on '+ $Sresult.ServerAddress + ' at ' + (get-date).ToLongTimeString());
20+
21+
$Lresult = New-XDDatabase -AdminAddress $env:COMPUTERNAME -SiteName $defaults.SITENAME -DataStore Logging -DatabaseServer $DBSERVER -DatabaseName $defaults.DBLOGNAME -DatabaseCredentials $Database_CredObject
22+
Write-Verbose ('Created Loging DB ' + $Lresult.Name + ' on '+ $Lresult.ServerAddress + ' at ' + (get-date).ToLongTimeString());
23+
24+
$Mresult = New-XDDatabase -AdminAddress $env:COMPUTERNAME -SiteName $defaults.SITENAME -DataStore Monitor -DatabaseServer $DBSERVER -DatabaseName $defaults.DBMONNAME -DatabaseCredentials $Database_CredObject
25+
Write-Verbose ('Created Monitor DB ' + $Mresult.Name + ' on '+ $Mresult.ServerAddress + ' at ' + (get-date).ToLongTimeString());
26+
Write-Verbose ('Finished DB Creation at ' + (get-date).ToLongTimeString());
27+
28+
}
29+
}
30+
#>

DSCResources/XD7Database/XD7Database.schema.mof

Whitespace-only changes.

DSCResources/XD7Role/Resources.psd1

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
ConvertFrom-StringData @'
2+
InvalidSourcePathError = Invalid XenDesktop source path '{0}' specified.
3+
NoValidSetupMediaError = No valid '{0}' setup media found in path '{1}'.
4+
SourceDirectorySet = Installation source path set to '{0}'.
5+
LogDirectorySet = Installation log directory set to '{0}'.
6+
InstallingRole = Installing Citrix XenDesktop 7.x '{0}' role.
7+
UninstallingRole = Uninstalling Citrix XenDesktop 7.x '{0}' role.
8+
StartingProcess = Starting process '{0}' with arguments '{1}'.
9+
StartingProcessAs = Starting process with user credential '{0}'.
10+
ProcessLaunched = Process Id '{0}' launched.
11+
WaitingForProcessToExit = Waiting for process Id '{0}' to exit..
12+
ProcessExited = Process Id '{0}' exited with code '{1}'.
13+
'@

DSCResources/XD7Role/XD7Role.Tests.ps1

Lines changed: 371 additions & 0 deletions
Large diffs are not rendered by default.

DSCResources/XD7Role/XD7Role.ps1

Lines changed: 241 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,241 @@
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

DSCResources/XD7Role/XD7Role.psm1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
## Dot source all (nested) .ps1 files in the folder, excluding Pester tests
2+
$moduleRoot = Split-Path -Parent $MyInvocation.MyCommand.Path;
3+
Get-ChildItem -Path $moduleRoot -Include *.ps1 -Exclude '*.Tests.ps1' -Recurse |
4+
ForEach-Object {
5+
Write-Verbose ('Dot sourcing ''{0}''.' -f $_.FullName);
6+
. $_.FullName;
7+
}
8+
9+
Export-ModuleMember -Function *-TargetResource
1.3 KB
Binary file not shown.

DSCResources/XD7Site/XD7Site.psm1

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<#
2+
function Create-Site {
3+
[CmdletBinding()]
4+
param (
5+
[Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [String] $LicenseServer,
6+
[Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [String] $DBserver,
7+
[Parameter(Mandatory)] [ValidateSet('PLT', 'ENT', 'APP', 'STD')] $LicenseServer_ProductEdition
8+
9+
10+
)
11+
12+
process {
13+
14+
$LicenseServerUri = 'https://'+$LicenseServer+':8083/'
15+
16+
Write-Verbose ('Starting Site Creation at ' + (get-date).ToLongTimeString());
17+
$NSresult = New-XDSite -AdminAddress $env:COMPUTERNAME -SiteName $defaults.SITENAME -DatabaseServer $DBserver -LoggingDatabaseName $defaults.DBLOGNAME -MonitorDatabaseName $defaults.DBMONNAME -SiteDatabaseName $defaults.DBSITENAME
18+
Write-Verbose ('Finished Creating Site at ' + (get-date).ToLongTimeString());
19+
20+
Write-Verbose ('Starting Site Configuration at ' + (get-date).ToLongTimeString());
21+
$XDLresult = Set-XDLicensing -AdminAddress $env:COMPUTERNAME -LicenseServerAddress $LicenseServer -LicenseServerPort 27000 | Out-Null
22+
$CSresult = Set-ConfigSite -AdminAddress $env:COMPUTERNAME -LicenseServerName $LicenseServer -LicenseServerUri $LicenseServerUri -LicenseServerPort $defaults.LICPORT -LicensingModel $defaults.LICMODEL -ProductCode $defaults.LICPRDCODE -ProductEdition $LicenseServer_ProductEdition | out-null
23+
$CSMresult = Set-ConfigSiteMetadata -AdminAddress $env:COMPUTERNAME -Name 'CertificateHash' -Value $(Get-LicCertificate -AdminAddress "https://$LicenseServer").CertHash | Out-Null
24+
Write-Verbose ('Finished Site Configuration at ' + (get-date).ToLongTimeString());
25+
26+
}
27+
}
28+
29+
function Join-Site {
30+
[CmdletBinding()]
31+
param (
32+
# Framework version to check against.
33+
[Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [string] $Controller
34+
35+
)
36+
37+
process {
38+
39+
Write-Verbose ('Attempting to Join Site using ' + $Controller + ' at ' + (get-date).ToLongTimeString());
40+
Add-XDController -AdminAddress $env:COMPUTERNAME -SiteControllerAddress $Controller
41+
Write-Verbose ('Joined Site at ' + (get-date).ToLongTimeString());
42+
}
43+
}
44+
#>

DSCResources/XD7Site/XD7Site.schema.mof

Whitespace-only changes.

LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 Iain Brighton
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
22+

0 commit comments

Comments
 (0)