-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathLabTest.ps1
More file actions
204 lines (194 loc) · 7.88 KB
/
LabTest.ps1
File metadata and controls
204 lines (194 loc) · 7.88 KB
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
function Set-LabSettings {
#process to create x number of workstation clients
#process to create x number of dummy clients
#find a solution to ensure the latest TP is installed
}
#endregion
#LAZY MODULE TESTING, WILL BE FIXED ONCE COMPLETED
#Who am i kidding this is how it will be for ever :)
foreach ($psfile in get-childitem -Filter *.ps1 | Where-Object { $_.name -notin ("NewENV.Tests.ps1", "labtest.ps1","new.tests.ps1","v5.testcases.ps1") }) {
. $psfile.FullName
}
#region import JSON Settings
$scriptpath = $PSScriptRoot
$config = Get-Content "$scriptpath\env.json" -Raw | ConvertFrom-Json
$envConfig = $config.ENVConfig | Where-Object { $_.env -eq $config.env }
$script:logfile = "$($envConfig.vmpath)\Build.log"
if (!(Test-Path $envConfig.vmpath)) { new-item -ItemType Directory -Force -Path $envConfig.vmpath | Out-Null }
Write-LogEntry -Type Information -Message "Start of build process for $($config.env) ------"
$admpwd = $envConfig.AdminPW
Write-LogEntry -Type Information -Message "Admin password set to: $admpwd"
$localadmin = new-object -typename System.Management.Automation.PSCredential -argumentlist "administrator", (ConvertTo-SecureString -String $admpwd -AsPlainText -Force)
$domuser = new-object -typename System.Management.Automation.PSCredential -argumentlist "$($envconfig.DomainNetBiosName)\administrator", (ConvertTo-SecureString -String $admpwd -AsPlainText -Force)
$vmpath = $envConfig.VMPath
Write-LogEntry -Type Information -Message "Path for VHDXs set to: $vmpath"
$swname = $envConfig.SwitchName
Write-LogEntry -Type Information -Message "vSwitch name is: $swname"
$ipsub = $envConfig.ipsubnet
Write-LogEntry -type Information -Message "IP Subnet used for this lab is: $ipsub"
$DomainFQDN = $envconfig.DomainFQDN
Write-LogEntry -Type Information -Message "Fully Quilified Domain Name is: $domainfqdn"
$RRASname = $Config.RRASname
Write-LogEntry -Type Information -Message "Routing and Remote Access Services server name is: $RRASName"
$RefVHDX = $config.REFVHDX
Write-LogEntry -Type Information -Message "Path to Reference VHDX is: $RefVHDX"
$domainnetbios = $envconfig.DomainNetBiosName
Write-LogEntry -Type Information -Message "WINNT domain name is: $domainnetbios"
$cmsitecode = $envConfig.CMSiteCode
Write-LogEntry -Type Information -Message "SCCM Site code is: $cmsitecode"
$SCCMDLPreDown = $config.SCCMDLPreDown
Write-LogEntry -Type Information -Message "SCCM Content was Predownloaded: $($sccmdlpredown -eq 1)"
$vmsnapshot = if ($config.Enablesnapshot -eq 1) { $true }else { $false }
Write-LogEntry -Type Information -Message "Snapshots have been: $vmsnapshot"
$unattendpath = $config.REFVHDX -replace ($config.REFVHDX.split('\') | Select-Object -last 1), "Unattended.xml"
Write-LogEntry -Type Information -Message "Windows 2016 unattend file is: $unattendpath"
$SCCMENVType = $Config.SCCMENVType
$SCCMVer = $config.SCCMVersion
#$servertemplates = (Get-Content "$scriptpath\SVRTemplates.json" -Raw | ConvertFrom-Json).ServerTemplates
#endregion
#region ENVConfig
$envconfig = [env]::new()
$envconfig.vmpath = $vmpath
$envConfig.RefVHDX = $RefVHDX
$envConfig.Win16ISOPath = $config.WIN16ISO
$envConfig.Win16Net35Cab = $config.WINNET35CAB
$envConfig.network = $swname
$envconfig.DefaultPwd = $admpwd
$envConfig.Save("$vmpath`\envconfig.json")
#endregion
#region RRASConfig
$RRASConfig = [RRAS]::new()
$RRASConfig.name = $RRASname
$RRASConfig.cores = 1
$RRASConfig.ram = 4
$RRASConfig.ipaddress = "$ipsub`1"
$RRASConfig.network = $swname
$RRASConfig.localadmin = $localadmin
$RRASConfig.vmSnapshotenabled = $false
$RRASConfig.VHDXpath = "$(split-path $vmpath)\RRASc.vhdx"
$RRASConfig.RefVHDX = $RefVHDX
$RRASConfig.Save("$(split-path $vmpath)\RRASConfig.json")
#endregion
#region DCConfig
$DCConfig = [DC]::new()
$DCConfig.Name = "$($config.env)`DC"
$DCConfig.cores = 1
$DCConfig.Ram = 4
$DCConfig.IPAddress = "$ipsub`10"
$DCConfig.network = $swname
$DCConfig.VHDXpath = "$vmpath\$($config.env)`DCc.vhdx"
$DCConfig.localadmin = $localadmin
$DCConfig.domainFQDN = $domainfqdn
$DCConfig.AdmPwd = $admpwd
$DCConfig.domainuser = $domuser
$DCConfig.VMSnapshotenabled = $false
$DCConfig.refvhdx = $RefVHDX
$DCConfig.Save("$vmpath\dcconfig.json")
#endregion
#region CMConfig - Primary Server
if ($SCCMENVType -eq "PRI") {
$CMConfig = [CM]::new()
$CMConfig.name = "$($config.env)`CM"
$CMConfig.cores = 4
$CMConfig.ram = 12
$CMConfig.IPAddress = "$ipsub`11"
$CMConfig.network = $swname
$CMConfig.VHDXpath = "$vmpath\$($config.env)`CMc.vhdx"
$CMConfig.localadmin = $localadmin
$CMConfig.domainuser = $domuser
$CMConfig.AdmPwd = $admpwd
$CMConfig.domainFQDN = $domainfqdn
$CMConfig.VMSnapshotenabled = $false
$CMConfig.cmsitecode = $cmsitecode
$CMConfig.SCCMDLPreDownloaded = $sccmdlpredown
$CMConfig.DCIP = $DCConfig.IPAddress
$CMConfig.RefVHDX = $RefVHDX
$CMConfig.SQLISO = $config.SQLISO
$CMConfig.SCCMPath = $config.SCCMPath
$CMConfig.ADKPath = $config.ADKPATH
$CMConfig.domainnetbios = $domainnetbios
$CMConfig.CMServerType = "PRI"
$CMConfig.SCCMVer = $SCCMVer
$CMConfig.save("$vmpath\cmconfig.json")
}
#endregion
#region CMConfig - CAS ENV
else {
$CMCASConfig = [CM]::new()
$CMCASConfig.name = "$($config.env)`CMCAS"
$CMCASConfig.cores = 4
$CMCASConfig.ram = 12
$CMCASConfig.IPAddress = "$ipsub`11"
$CMCASConfig.network = $swname
$CMCASConfig.VHDXpath = "$vmpath\$($config.env)`CMCASc.vhdx"
$CMCASConfig.localadmin = $localadmin
$CMCASConfig.domainuser = $domuser
$CMCASConfig.AdmPwd = $admpwd
$CMCASConfig.domainFQDN = $domainfqdn
$CMCASConfig.VMSnapshotenabled = $false
$CMCASConfig.cmsitecode = $cmsitecode
$CMCASConfig.SCCMDLPreDownloaded = $sccmdlpredown
$CMCASConfig.DCIP = $DCConfig.IPAddress
$CMCASConfig.RefVHDX = $RefVHDX
$CMCASConfig.SQLISO = $config.SQLISO
$CMCASConfig.SCCMPath = $config.SCCMPath
$CMCASConfig.ADKPath = $config.ADKPATH
$CMCASConfig.domainnetbios = $domainnetbios
$CMCASConfig.CMServerType = "CAS"
$CMConfig.SCCMVer = $SCCMVer
$CMCASConfig.save("$vmpath\cmCASconfig.json")
$CMCASPRIConfig = [CM]::new()
$CMCASPRIConfig.name = "$($config.env)`CMCASPRI"
$CMCASPRIConfig.cores = 4
$CMCASPRIConfig.ram = 12
$CMCASPRIConfig.IPAddress = "$ipsub`12"
$CMCASPRIConfig.network = $swname
$CMCASPRIConfig.VHDXpath = "$vmpath\$($config.env)`CMCASPRIc.vhdx"
$CMCASPRIConfig.localadmin = $localadmin
$CMCASPRIConfig.domainuser = $domuser
$CMCASPRIConfig.AdmPwd = $admpwd
$CMCASPRIConfig.domainFQDN = $domainfqdn
$CMCASPRIConfig.VMSnapshotenabled = $false
$CMCASPRIConfig.cmsitecode = $cmsitecode
$CMCASPRIConfig.SCCMDLPreDownloaded = $sccmdlpredown
$CMCASPRIConfig.DCIP = $DCConfig.IPAddress
$CMCASPRIConfig.RefVHDX = $RefVHDX
$CMCASPRIConfig.SQLISO = $config.SQLISO
$CMCASPRIConfig.SCCMPath = $config.SCCMPath
$CMCASPRIConfig.ADKPath = $config.ADKPATH
$CMCASPRIConfig.domainnetbios = $domainnetbios
$CMCASPRIConfig.CMServerType = "CASPRI"
$CMConfig.SCCMVer = $SCCMVer
$CMCASPRIConfig.CASIPAddress = $CMCASConfig.IPAddress
$CMCASPRIConfig.save("$vmpath\cmCASPRIconfig.json")
}
#endregion
#region CAConfig
$CAConfig = [CA]::new()
$CAConfig.name = "$($config.env)`CA"
$CAConfig.cores = 1
$CAConfig.Ram = 4
$CAConfig.IPAddress = "$ipsub`20"
$CAConfig.domainuser = $domuser
$CAConfig.localadmin = $localadmin
$CAConfig.network = $swname
$CAConfig.VHDXpath = "$vmpath\$($config.env)`CAc.vhdx"
$CAConfig.domainFQDN = $DomainFQDN
$CAConfig.VMSnapshotenabled = $false
$CAConfig.refvhdx = $RefVHDX
$CAConfig.DCIP = $DCConfig.IPAddress
$CAConfig.save("$vmpath\CAConfig.json")
#endregion
#region create VMs
new-env -ENVConfig $envconfig
new-RRASServer -RRASConfig $RRASConfig
new-DC -DCConfig $DCConfig
New-CAServer -CAConfig $CAConfig
if ($SCCMENVType -eq "PRI") {
new-SCCMServer -CMConfig $CMConfig
}
else {
new-SCCMServer -CMConfig $CMCASConfig
new-SCCMServer -CMConfig $CMCASPRIConfig
}
#endregion