DSCResources/ROALab/ROALab.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
configuration ROALab {
<#
    .SYNOPSIS
        Creates a RES ONE Automation single node lab deployment
    .NOTES
        The Console, Dispatcher and Agent MSIs need to be manually extracted first!
        7.0.0.0 is RES Automation Manager 2014
        7.5.0.0 is RES ONE Automation 2015
        7.5.1.0 is RES ONE Automation 2015 SR1
#>

    [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWriteHost', '')]
    param (
        ## RES ONE Automation database server name/instance (equivalient to DBSERVER).
        [Parameter(Mandatory)]
        [ValidateNotNullOrEmpty()]
        [System.String] $DatabaseServer,

        ## RES ONE Automation database name (equivalient to DBNAME).
        [Parameter(Mandatory)]
        [ValidateNotNullOrEmpty()]
        [System.String] $DatabaseName,

        ## Microsoft SQL username/password to connect to the RES ONE Automation database (equivalent to DBUSER/DBPASSWORD).
        [Parameter(Mandatory)]
        [ValidateNotNull()]
        [System.Management.Automation.PSCredential]
        [System.Management.Automation.Credential()] $Credential,

        ## Microsoft SQL database credentials used to create the database (equivalient to DBCREATEUSER/DBCREATEPASSWORD).
        [Parameter(Mandatory)]
        [ValidateNotNull()]
        [System.Management.Automation.PSCredential]
        [System.Management.Automation.Credential()] $SQLCredential,

        ## File path containing the RES ONE Automation MSIs or the literal path to the legacy console/Sync Tool MSI.
        [Parameter(Mandatory)]
        [ValidateNotNullOrEmpty()]
        [System.String] $Path,

        ## RES ONE Automation component version to be installed, i.e. 7.5.1.0
        [Parameter(Mandatory)]
        [ValidateNotNullOrEmpty()]
        [System.String] $Version,

        ## File path to RES ONE Automation license file.
        [Parameter()]
        [ValidateNotNullOrEmpty()]
        [System.String] $LicensePath,

        ## File path to RES ONE Automation building blocks to import.
        [Parameter()]
        [ValidateNotNullOrEmpty()]
        [System.String] $BuildingBlockPath,

        ## Credential used to import the RES ONE Automation building blocks.
        [Parameter()]
        [ValidateNotNull()]
        [System.Management.Automation.PSCredential]
        [System.Management.Automation.Credential()] $BuildingBlockCredential,

        ## Credential used to import the building blocks is a RES ONE Automation user.
        [Parameter()]
        [ValidateNotNull()]
        [System.Boolean] $IsBuildingBlockCredentialRESONEAutomationUser,

        ## Delete the building block from disk after import.
        [Parameter()]
        [System.Boolean] $DeleteBuildingBlock,

        [Parameter()]
        [ValidateSet('Present','Absent')]
        [System.String] $Ensure = 'Present'
    )

    Write-Host ' Starting "ROALab".' -ForegroundColor Gray;

    Import-DscResource -ModuleName xPSDesiredStateConfiguration, xNetworking;

    ## Can't import RESONEServiceStore composite resource due to circular references!
    Import-DscResource -Name ROADatabase, ROADispatcher, ROADatabaseAgent, ROABuildingBlock;

    ## If path -match '\.msi$', throw.
    if ($Path -match '\.msi$') {
        throw "Specified path '$Path' does not point to a directory.";
    }

    if ($Ensure -eq 'Present') {

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

            Write-Host ' Processing "ROALab\ROALabDatabase" with "LicensePath".' -ForegroundColor Gray;
            ROADatabase 'ROALabDatabase' {
                DatabaseServer = $DatabaseServer;
                DatabaseName   = $DatabaseName;
                Path           = $Path;
                Version        = $Version;
                SQLCredential  = $SQLCredential;
                Credential     = $Credential;
                IsLiteralPath  = $false;
                LicensePath    = $LicensePath;
                Ensure         = $Ensure;
            }
        }
        else {

            Write-Host ' Processing "ROALab\ROALabDatabase".' -ForegroundColor Gray;
            ROADatabase 'ROALabDatabase' {
                DatabaseServer = $DatabaseServer;
                DatabaseName   = $DatabaseName;
                Path           = $Path;
                Version        = $Version;
                SQLCredential  = $SQLCredential;
                Credential     = $Credential;
                IsLiteralPath  = $false;
                Ensure         = $Ensure;
            }
        }

        Write-Host ' Processing "ROALab\ROALabDispatcher".' -ForegroundColor Gray;
        ROADispatcher 'ROALabDispatcher' {
            DatabaseServer = $DatabaseServer;
            DatabaseName   = $DatabaseName;
            Path           = $Path;
            Version        = $Version;
            Credential     = $Credential;
            Ensure         = $Ensure;
            IsLiteralPath  = $false;
            DependsOn      = '[ROADatabase]ROALabDatabase';
        }

        Write-Host ' Processing "ROALab\ROALabDatabaseAgent".' -ForegroundColor Gray;
        ROADatabaseAgent 'ROALabDatabaseAgent' {
            DatabaseServer = $DatabaseServer;
            DatabaseName   = $DatabaseName;
            Path           = $Path;
            Version        = $Version;
            Credential     = $Credential;
            Ensure         = $Ensure;
            IsLiteralPath  = $false;
            DependsOn      = '[ROADispatcher]ROALabDispatcher';
        }

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

            Write-Host ' Processing "ROALab\ROALabBuildingBlock".' -ForegroundColor Gray;
            ROABuildingBlock 'ROALabBuildingBlock' {
                Path                         = $BuildingBlockPath;
                Credential                   = $BuildingBlockCredential;
                IsRESONEAutomationCredential = $IsBuildingBlockCredentialRESONEAutomationUser;
                DeleteFromDisk               = $DeleteBuildingBlock;
                DependsOn                    =  '[ROADatabase]ROALabDatabase';
            }
        }

    }
    elseif ($Ensure -eq 'Absent') {

        Write-Host ' Processing "ROALab\ROALabDatabaseAgent".' -ForegroundColor Gray;
        ROADatabaseAgent 'ROALabDatabaseAgent' {
            DatabaseServer = $DatabaseServer;
            DatabaseName   = $DatabaseName;
            Path           = $Path;
            Version        = $Version;
            Credential     = $Credential;
            IsLiteralPath  = $false;
            Ensure         = $Ensure;
        }

         Write-Host ' Processing "ROALab\ROALabDispatcher".' -ForegroundColor Gray;
         ROADispatcher 'ROALabDispatcher' {
            DatabaseServer = $DatabaseServer;
            DatabaseName   = $DatabaseName;
            Path           = $Path;
            Version        = $Version;
            Credential     = $Credential;
            IsLiteralPath  = $false;
            Ensure         = $Ensure;
            DependsOn      = '[ROADatabaseAgent]ROALabDatabaseAgent';
        }

        Write-Host ' Processing "ROALab\ROALabDatabase".' -ForegroundColor Gray;
        ROADatabase 'ROALabDatabase' {
            DatabaseServer = $DatabaseServer;
            DatabaseName   = $DatabaseName;
            Path           = $Path;
            Version        = $Version;
            SQLCredential  = $SQLCredential;
            Credential     = $Credential;
            IsLiteralPath  = $false;
            Ensure         = $Ensure;
            DependsOn      = '[ROADispatcher]ROALabDispatcher';
        }

    }

    Write-Host ' Processing "ROALab\RESONEAutomationFirewall".' -ForegroundColor Gray;
    xFirewall 'RESONEAutomationFirewall' {
        Name        = 'RESONEAutomation-TCP-3163-In';
        Group       = 'RES ONE Automation';
        DisplayName = 'RES ONE Automation (Dispatcher)';
        Action      = 'Allow';
        Direction   = 'Inbound';
        Enabled     = $true;
        Profile     = 'Any';
        Protocol    = 'TCP';
        LocalPort   = 3163;
        Description = 'RES ONE Automation Dispatcher Service';
        Ensure      = $Ensure;
        DependsOn   = '[ROADispatcher]ROALabDispatcher';
    }

    Write-Host ' Processing "ROALab\RESONEAutomationDiscoveryFirewall".' -ForegroundColor Gray;
    xFirewall 'RESONEAutomationDiscoveryFirewall' {
        Name        = 'RESONEAutomation-UDP-3163-In';
        Group       = 'RES ONE Automation';
        DisplayName = 'RES ONE Automation (Dispatcher Discovery)';
        Action      = 'Allow';
        Direction   = 'Inbound';
        Enabled     = $true;
        Profile     = 'Any';
        Protocol    = 'UDP';
        LocalPort   = 3163;
        Description = 'RES ONE Automation Dispatcher Service Discovery';
        Ensure      = $Ensure;
        DependsOn   = '[ROADispatcher]ROALabDispatcher';
    }

    Write-Host ' Ending "ROALab".' -ForegroundColor Gray;

} #end configuration ROALab