DSCResources/XD7LabSessionHost/XD7LabSessionHost.schema.psm1

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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
configuration XD7LabSessionHost {
    param (
        ## Citrix XenDesktop installation source root
        [Parameter(Mandatory)]
        [ValidateNotNullOrEmpty()]
        [System.String] $XenDesktopMediaPath,

        ## Citrix XenDesktop delivery controller address(es)
        [Parameter(Mandatory)]
        [ValidateNotNullOrEmpty()]
        [System.String[]] $ControllerAddress,

        ## RDS license server
        [Parameter(Mandatory)]
        [ValidateNotNullOrEmpty()]
        [System.String] $RDSLicenseServer,

        ## Users/groups to add to the local Remote Desktop Users group
        [Parameter()]
        [ValidateNotNullOrEmpty()]
        [System.String[]] $RemoteDesktopUsers,

        ## Active Directory domain account used to communicate with AD for Remote Desktop Users
        [Parameter()]
        [ValidateNotNull()]
        [System.Management.Automation.PSCredential]
        [System.Management.Automation.CredentialAttribute()]
        $Credential
    )

    Import-DscResource -ModuleName XenDesktop7;

    foreach ($feature in @('RDS-RD-Server', 'Remote-Assistance', 'Desktop-Experience')) {

        WindowsFeature $feature {
            Name = $feature;
            Ensure = 'Present';
        }
    }

    XD7VDAFeature 'XD7SessionVDA' {
        Role = 'SessionVDA';
        SourcePath = $XenDesktopMediaPath;
        DependsOn = '[WindowsFeature]RDS-RD-Server';
    }

    foreach ($controller in $ControllerAddress) {

        XD7VDAController "XD7VDA_$controller" {
            Name = $controller;
            DependsOn = '[XD7VDAFeature]XD7SessionVDA';
        }
    }

    if ($PSBoundParameters.ContainsKey('RemoteDesktopUsers')) {

        if ($PSBoundParameters.ContainsKey('Credential')) {

            Group 'RemoteDesktopUsers' {
                GroupName = 'Remote Desktop Users';
                MembersToInclude = $RemoteDesktopUsers;
                Ensure = 'Present';
                Credential = $Credential;
            }
        }
        else {

            Group 'RemoteDesktopUsers' {
                GroupName = 'Remote Desktop Users';
                MembersToInclude = $RemoteDesktopUsers;
                Ensure = 'Present';
            }
        } #end if Credential

    } #end if Remote Desktop Users

    Registry 'RDSLicenseServer' {
        Key = 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\TermService\Parameters\LicenseServers';
        ValueName = 'SpecifiedLicenseServers';
        ValueData = $RDSLicenseServer;
        ValueType = 'MultiString';
    }

    Registry 'RDSLicensingMode' {
        Key = 'HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Terminal Server\RCM\Licensing Core';
        ValueName = 'LicensingMode';
        ValueData = '4'; # 2 = Per Device, 4 = Per User
        ValueType = 'Dword';
    }

} #end configuration XD7LabSessionHost