forked from lamw/vsphere-automated-lab-deployment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vsphere-6.0standard-lab-deployment.ps1
550 lines (481 loc) · 26.5 KB
/
vsphere-6.0standard-lab-deployment.ps1
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
# Author: William Lam
# Website: www.virtuallyghetto.com
# Description: PowerCLI script to deploy a fully functional vSphere 6.0 lab consisting of 3
# Nested ESXi hosts enable w/vSAN + VCSA 6.0u2. Expects a single physical ESXi host
# as the endpoint and all four VMs will be deployed to physical ESXi host
# Reference: http://www.virtuallyghetto.com/2016/11/vghetto-automated-vsphere-lab-deployment-for-vsphere-6-0u2-vsphere-6-5.html
# Credit: Thanks to Alan Renouf as I borrowed some of his PCLI code snippets :)
#
# Changelog
# 11/22/16
# * Automatically handle Nested ESXi on vSAN
# 01/20/17
# * Resolved "Another task in progress" thanks to Jason M
# 02/12/17
# * Support for deploying to VC Target
# * Support for enabling SSH on VCSA
# * Added option to auto-create vApp Container for VMs
# * Added pre-check for required files
# 02/17/17
# * Added missing dvFilter param to eth1 (missing in Nested ESXi OVA)
# Physical ESXi host or vCenter Server to deploy vSphere 6.0 lab
$VIServer = "vcenter.primp-industries.com"
$VIUsername = "[email protected]"
$VIPassword = "!!!MySuperDuperSecurePassword!!!"
# Specifies whether deployment is to an ESXi host or vCenter Server
# Use either ESXI or VCENTER
$DeploymentTarget = "VCENTER"
# Full Path to both the Nested ESXi 6.0 VA + extracted VCSA 6.0 ISO
$NestedESXiApplianceOVA = "C:\Users\primp\Desktop\Nested_ESXi6.x_Appliance_Template_v5.ova"
$VCSAInstallerPath = "C:\Users\primp\Desktop\VMware-VCSA-all-6.0.0-3634788"
# Nested ESXi VMs to deploy
$NestedESXiHostnameToIPs = @{
"vesxi60-1" = "172.30.0.85"
"vesxi60-2" = "172.30.0.86"
"vesxi60-3" = "172.30.0.87"
}
# Nested ESXi VM Resources
$NestedESXivCPU = "2"
$NestedESXivMEM = "6" #GB
$NestedESXiCachingvDisk = "4" #GB
$NestedESXiCapacityvDisk = "8" #GB
# VCSA Deployment Configuration
$VCSADeploymentSize = "tiny"
$VCSADisplayName = "vcenter60-1"
$VCSAIPAddress = "172.30.0.50"
$VCSAHostname = "vcenter60-1.primp-industries.com" #Change to IP if you don't have valid DNS
$VCSAPrefix = "24"
$VCSASSODomainName = "vsphere.local"
$VCSASSOSiteName = "virtuallyGhetto"
$VCSASSOPassword = "VMware1!"
$VCSARootPassword = "VMware1!"
$VCSASSHEnable = "true"
# General Deployment Configuration for both Nested ESXi VMs + VCSA
$VMNetwork = "access333"
$VMDatastore = "himalaya-local-SATA-dc3500-3"
$VMNetmask = "255.255.255.0"
$VMGateway = "172.30.0.1"
$VMDNS = "172.30.0.100"
$VMNTP = "pool.ntp.org"
$VMPassword = "vmware123"
$VMDomain = "primp-industries.com"
$VMSyslog = "172.30.0.50"
# Applicable to Nested ESXi only
$VMSSH = "true"
$VMVMFS = "false"
# Applicable to VC Deployment Target only
$VMCluster = "Primp-Cluster"
# Name of new vSphere Datacenter/Cluster when VCSA is deployed
$NewVCDatacenterName = "Datacenter"
$NewVCVSANClusterName = "VSAN-Cluster"
#### DO NOT EDIT BEYOND HERE ####
$verboseLogFile = "vsphere60-lab-deployment.log"
$vSphereVersion = "6.0u2"
$deploymentType = "Standard"
$random_string = -join ((65..90) + (97..122) | Get-Random -Count 8 | % {[char]$_})
$VAppName = "Nested-vSphere-Lab-$vSphereVersion-$random_string"
$preCheck = 1
$confirmDeployment = 1
$deployNestedESXiVMs = 1
$deployVCSA = 1
$setupNewVC = 1
$addESXiHostsToVC = 1
$configureVSANDiskGroups = 1
$clearVSANHealthCheckAlarm = 1
$moveVMsIntovApp = 1
$StartTime = Get-Date
Function My-Logger {
param(
[Parameter(Mandatory=$true)]
[String]$message
)
$timeStamp = Get-Date -Format "MM-dd-yyyy_hh:mm:ss"
Write-Host -NoNewline -ForegroundColor White "[$timestamp]"
Write-Host -ForegroundColor Green " $message"
$logMessage = "[$timeStamp] $message"
$logMessage | Out-File -Append -LiteralPath $verboseLogFile
}
if($preCheck -eq 1) {
if(!(Test-Path $NestedESXiApplianceOVA)) {
Write-Host -ForegroundColor Red "`nUnable to find $NestedESXiApplianceOVA ...`nexiting"
exit
}
if(!(Test-Path $VCSAInstallerPath)) {
Write-Host -ForegroundColor Red "`nUnable to find $VCSAInstallerPath ...`nexiting"
exit
}
}
if($confirmDeployment -eq 1) {
Write-Host -ForegroundColor Magenta "`nPlease confirm the following configuration will be deployed:`n"
Write-Host -ForegroundColor Yellow "---- vSphere Automated Lab Deployment Configuration ---- "
Write-Host -NoNewline -ForegroundColor Green "Deployment Type: "
Write-Host -ForegroundColor White $deploymentType
Write-Host -NoNewline -ForegroundColor Green "vSphere Version: "
Write-Host -ForegroundColor White "vSphere $vSphereVersion"
Write-Host -NoNewline -ForegroundColor Green "Nested ESXi Image Path: "
Write-Host -ForegroundColor White $NestedESXiApplianceOVA
Write-Host -NoNewline -ForegroundColor Green "VCSA Image Path: "
Write-Host -ForegroundColor White $VCSAInstallerPath
if($DeploymentTarget -eq "ESXI") {
Write-Host -ForegroundColor Yellow "`n---- Physical ESXi Configuration ----"
Write-Host -NoNewline -ForegroundColor Green "ESXi Address: "
} else {
Write-Host -ForegroundColor Yellow "`n---- vCenter Server Configuration ----"
Write-Host -NoNewline -ForegroundColor Green "vCenter Server Address: "
}
Write-Host -ForegroundColor White $VIServer
Write-Host -NoNewline -ForegroundColor Green "Username: "
Write-Host -ForegroundColor White $VIUsername
Write-Host -NoNewline -ForegroundColor Green "VM Network: "
Write-Host -ForegroundColor White $VMNetwork
Write-Host -NoNewline -ForegroundColor Green "VM Storage: "
Write-Host -ForegroundColor White $VMDatastore
if($DeploymentTarget -eq "VCENTER") {
Write-Host -NoNewline -ForegroundColor Green "VM Cluster: "
Write-Host -ForegroundColor White $VMCluster
Write-Host -NoNewline -ForegroundColor Green "VM vApp: "
Write-Host -ForegroundColor White $VAppName
}
Write-Host -ForegroundColor Yellow "`n---- vESXi Configuration ----"
Write-Host -NoNewline -ForegroundColor Green "# of Nested ESXi VMs: "
Write-Host -ForegroundColor White $NestedESXiHostnameToIPs.count
Write-Host -NoNewline -ForegroundColor Green "vCPU: "
Write-Host -ForegroundColor White $NestedESXivCPU
Write-Host -NoNewline -ForegroundColor Green "vMEM: "
Write-Host -ForegroundColor White "$NestedESXivMEM GB"
Write-Host -NoNewline -ForegroundColor Green "Caching VMDK: "
Write-Host -ForegroundColor White "$NestedESXiCachingvDisk GB"
Write-Host -NoNewline -ForegroundColor Green "Capacity VMDK: "
Write-Host -ForegroundColor White "$NestedESXiCapacityvDisk GB"
Write-Host -NoNewline -ForegroundColor Green "IP Address(s): "
Write-Host -ForegroundColor White $NestedESXiHostnameToIPs.Values
Write-Host -NoNewline -ForegroundColor Green "Netmask "
Write-Host -ForegroundColor White $VMNetmask
Write-Host -NoNewline -ForegroundColor Green "Gateway: "
Write-Host -ForegroundColor White $VMGateway
Write-Host -NoNewline -ForegroundColor Green "DNS: "
Write-Host -ForegroundColor White $VMDNS
Write-Host -NoNewline -ForegroundColor Green "NTP: "
Write-Host -ForegroundColor White $VMNTP
Write-Host -NoNewline -ForegroundColor Green "Syslog: "
Write-Host -ForegroundColor White $VMSyslog
Write-Host -NoNewline -ForegroundColor Green "Enable SSH: "
Write-Host -ForegroundColor White $VMSSH
Write-Host -NoNewline -ForegroundColor Green "Create VMFS Volume: "
Write-Host -ForegroundColor White $VMVMFS
Write-Host -NoNewline -ForegroundColor Green "Root Password: "
Write-Host -ForegroundColor White $VMPassword
Write-Host -ForegroundColor Yellow "`n---- VCSA Configuration ----"
Write-Host -NoNewline -ForegroundColor Green "Deployment Size: "
Write-Host -ForegroundColor White $VCSADeploymentSize
Write-Host -NoNewline -ForegroundColor Green "SSO Domain: "
Write-Host -ForegroundColor White $VCSASSODomainName
Write-Host -NoNewline -ForegroundColor Green "SSO Site: "
Write-Host -ForegroundColor White $VCSASSOSiteName
Write-Host -NoNewline -ForegroundColor Green "SSO Password: "
Write-Host -ForegroundColor White $VCSASSOPassword
Write-Host -NoNewline -ForegroundColor Green "Root Password: "
Write-Host -ForegroundColor White $VCSARootPassword
Write-Host -NoNewline -ForegroundColor Green "Enable SSH: "
Write-Host -ForegroundColor White $VCSASSHEnable
Write-Host -NoNewline -ForegroundColor Green "Hostname: "
Write-Host -ForegroundColor White $VCSAHostname
Write-Host -NoNewline -ForegroundColor Green "IP Address: "
Write-Host -ForegroundColor White $VCSAIPAddress
Write-Host -NoNewline -ForegroundColor Green "Netmask "
Write-Host -ForegroundColor White $VMNetmask
Write-Host -NoNewline -ForegroundColor Green "Gateway: "
Write-Host -ForegroundColor White $VMGateway
Write-Host -ForegroundColor Magenta "`nWould you like to proceed with this deployment?`n"
$answer = Read-Host -Prompt "Do you accept (Y or N)"
if($answer -ne "Y" -or $answer -ne "y") {
exit
}
Clear-Host
}
My-Logger "Connecting to $VIServer ..."
$viConnection = Connect-VIServer $VIServer -User $VIUsername -Password $VIPassword -WarningAction SilentlyContinue
if($DeploymentTarget -eq "ESXI") {
$datastore = Get-Datastore -Server $viConnection -Name $VMDatastore
$vmhost = Get-VMHost -Server $viConnection
$network = Get-VirtualPortGroup -Server $viConnection -Name $VMNetwork -VMHost $vmhost
if($datastore.Type -eq "vsan") {
My-Logger "VSAN Datastore detected, enabling Fake SCSI Reservations ..."
Get-AdvancedSetting -Entity $vmhost -Name "VSAN.FakeSCSIReservations" | Set-AdvancedSetting -Value 1 -Confirm:$false | Out-File -Append -LiteralPath $verboseLogFile
}
} else {
$datastore = Get-Datastore -Server $viConnection -Name $VMDatastore | Select -First 1
$network = Get-VirtualPortGroup -Server $viConnection -Name $VMNetwork | Select -First 1
$cluster = Get-Cluster -Server $viConnection -Name $VMCluster
$datacenter = $cluster | Get-Datacenter
$vmhost = $cluster | Get-VMHost | Select -First 1
}
if($deployNestedESXiVMs -eq 1) {
if($DeploymentTarget -eq "ESXI") {
$NestedESXiHostnameToIPs.GetEnumerator() | Sort-Object -Property Value | Foreach-Object {
$VMName = $_.Key
$VMIPAddress = $_.Value
My-Logger "Deploying Nested ESXi VM $VMName ..."
$vm = Import-VApp -Server $viConnection -Source $NestedESXiApplianceOVA -Name $VMName -VMHost $vmhost -Datastore $datastore -DiskStorageFormat thin
My-Logger "Updating VM Network ..."
foreach($networkAdapter in ($vm | Get-NetworkAdapter))
{
My-Logger "Configuring adapter $networkAdapter in $vm"
$networkAdapter | Set-NetworkAdapter -Portgroup $network -confirm:$false | Out-File -Append -LiteralPath $verboseLogFile
sleep 5
}
My-Logger "Updating vCPU Count to $NestedESXivCPU & vMEM to $NestedESXivMEM GB ..."
Set-VM -Server $viConnection -VM $vm -NumCpu $NestedESXivCPU -MemoryGB $NestedESXivMEM -Confirm:$false | Out-File -Append -LiteralPath $verboseLogFile
My-Logger "Updating vSAN Caching VMDK size to $NestedESXiCachingvDisk GB ..."
Get-HardDisk -Server $viConnection -VM $vm -Name "Hard disk 2" | Set-HardDisk -CapacityGB $NestedESXiCachingvDisk -Confirm:$false | Out-File -Append -LiteralPath $verboseLogFile
My-Logger "Updating vSAN Capacity VMDK size to $NestedESXiCapacityvDisk GB ..."
Get-HardDisk -Server $viConnection -VM $vm -Name "Hard disk 3" | Set-HardDisk -CapacityGB $NestedESXiCapacityvDisk -Confirm:$false | Out-File -Append -LiteralPath $verboseLogFile
$orignalExtraConfig = $vm.ExtensionData.Config.ExtraConfig
$a = New-Object VMware.Vim.OptionValue
$a.key = "guestinfo.hostname"
$a.value = $VMName
$b = New-Object VMware.Vim.OptionValue
$b.key = "guestinfo.ipaddress"
$b.value = $VMIPAddress
$c = New-Object VMware.Vim.OptionValue
$c.key = "guestinfo.netmask"
$c.value = $VMNetmask
$d = New-Object VMware.Vim.OptionValue
$d.key = "guestinfo.gateway"
$d.value = $VMGateway
$e = New-Object VMware.Vim.OptionValue
$e.key = "guestinfo.dns"
$e.value = $VMDNS
$f = New-Object VMware.Vim.OptionValue
$f.key = "guestinfo.domain"
$f.value = $VMDomain
$g = New-Object VMware.Vim.OptionValue
$g.key = "guestinfo.ntp"
$g.value = $VMNTP
$h = New-Object VMware.Vim.OptionValue
$h.key = "guestinfo.syslog"
$h.value = $VMSyslog
$i = New-Object VMware.Vim.OptionValue
$i.key = "guestinfo.password"
$i.value = $VMPassword
$j = New-Object VMware.Vim.OptionValue
$j.key = "guestinfo.ssh"
$j.value = $VMSSH
$k = New-Object VMware.Vim.OptionValue
$k.key = "guestinfo.createvmfs"
$k.value = $VMVMFS
$l = New-Object VMware.Vim.OptionValue
$l.key = "ethernet1.filter4.name"
$l.value = "dvfilter-maclearn"
$m = New-Object VMware.Vim.OptionValue
$m.key = "ethernet1.filter4.onFailure"
$m.value = "failOpen"
$orignalExtraConfig+=$a
$orignalExtraConfig+=$b
$orignalExtraConfig+=$c
$orignalExtraConfig+=$d
$orignalExtraConfig+=$e
$orignalExtraConfig+=$f
$orignalExtraConfig+=$g
$orignalExtraConfig+=$h
$orignalExtraConfig+=$i
$orignalExtraConfig+=$j
$orignalExtraConfig+=$k
$orignalExtraConfig+=$l
$orignalExtraConfig+=$m
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$spec.ExtraConfig = $orignalExtraConfig
My-Logger "Adding guestinfo customization properties to $vmname ..."
$task = $vm.ExtensionData.ReconfigVM_Task($spec)
$task1 = Get-Task -Id ("Task-$($task.value)")
$task1 | Wait-Task | Out-Null
My-Logger "Powering On $vmname ..."
Start-VM -Server $viConnection -VM $vm -Confirm:$false | Out-File -Append -LiteralPath $verboseLogFile
}
} else {
$NestedESXiHostnameToIPs.GetEnumerator() | Sort-Object -Property Value | Foreach-Object {
$VMName = $_.Key
$VMIPAddress = $_.Value
$ovfconfig = Get-OvfConfiguration $NestedESXiApplianceOVA
$networkMapLabel = ($ovfconfig.ToHashTable().keys | where {$_ -Match "NetworkMapping"}).replace("NetworkMapping.","").replace("-","_").replace(" ","_")
$ovfconfig.NetworkMapping.$networkMapLabel.value = $VMNetwork
$ovfconfig.common.guestinfo.hostname.value = $VMName
$ovfconfig.common.guestinfo.ipaddress.value = $VMIPAddress
$ovfconfig.common.guestinfo.netmask.value = $VMNetmask
$ovfconfig.common.guestinfo.gateway.value = $VMGateway
$ovfconfig.common.guestinfo.dns.value = $VMDNS
$ovfconfig.common.guestinfo.domain.value = $VMDomain
$ovfconfig.common.guestinfo.ntp.value = $VMNTP
$ovfconfig.common.guestinfo.syslog.value = $VMSyslog
$ovfconfig.common.guestinfo.password.value = $VMPassword
if($VMSSH -eq "true") {
$VMSSHVar = $true
} else {
$VMSSHVar = $false
}
$ovfconfig.common.guestinfo.ssh.value = $VMSSHVar
My-Logger "Deploying Nested ESXi VM $VMName ..."
$vm = Import-VApp -Source $NestedESXiApplianceOVA -OvfConfiguration $ovfconfig -Name $VMName -Location $cluster -VMHost $vmhost -Datastore $datastore -DiskStorageFormat thin
# Add the dvfilter settings to the exisiting ethernet1 (not part of ova template)
My-Logger "Correcting missing dvFilter settings for Ethernet[1] ..."
$vm | New-AdvancedSetting -name "ethernet1.filter4.name" -value "dvfilter-maclearn" -confirm:$false | Out-File -Append -LiteralPath $verboseLogFile
$vm | New-AdvancedSetting -Name "ethernet1.filter4.onFailure" -value "failOpen" -confirm:$false | Out-File -Append -LiteralPath $verboseLogFile
My-Logger "Updating vCPU Count to $NestedESXivCPU & vMEM to $NestedESXivMEM GB ..."
Set-VM -Server $viConnection -VM $vm -NumCpu $NestedESXivCPU -MemoryGB $NestedESXivMEM -Confirm:$false | Out-File -Append -LiteralPath $verboseLogFile
My-Logger "Updating vSAN Caching VMDK size to $NestedESXiCachingvDisk GB ..."
Get-HardDisk -Server $viConnection -VM $vm -Name "Hard disk 2" | Set-HardDisk -CapacityGB $NestedESXiCachingvDisk -Confirm:$false | Out-File -Append -LiteralPath $verboseLogFile
My-Logger "Updating vSAN Capacity VMDK size to $NestedESXiCapacityvDisk GB ..."
Get-HardDisk -Server $viConnection -VM $vm -Name "Hard disk 3" | Set-HardDisk -CapacityGB $NestedESXiCapacityvDisk -Confirm:$false | Out-File -Append -LiteralPath $verboseLogFile
My-Logger "Powering On $vmname ..."
$vm | Start-Vm -RunAsync | Out-Null
}
}
}
if($deployVCSA -eq 1) {
# Deploy using the VCSA CLI Installer
if($DeploymentTarget -eq "ESXI") {
$config = (Get-Content -Raw "$($VCSAInstallerPath)\vcsa-cli-installer\templates\install\embedded_vCSA_on_ESXi.json") | convertfrom-json
$config.'target.vcsa'.esx.hostname = $VIServer
$config.'target.vcsa'.esx.username = $VIUsername
$config.'target.vcsa'.esx.password = $VIPassword
$config.'target.vcsa'.esx.datastore = $datastore
$config.'target.vcsa'.appliance.'deployment.network' = $VMNetwork
$config.'target.vcsa'.appliance.'thin.disk.mode' = $true
$config.'target.vcsa'.appliance.'deployment.option' = $VCSADeploymentSize
$config.'target.vcsa'.appliance.name = $VCSADisplayName
$config.'target.vcsa'.network.'ip.family' = "ipv4"
$config.'target.vcsa'.network.mode = "static"
$config.'target.vcsa'.network.ip = $VCSAIPAddress
$config.'target.vcsa'.network.'dns.servers'[0] = $VMDNS
$config.'target.vcsa'.network.'dns.servers'[1] = $null
$config.'target.vcsa'.network.prefix = $VCSAPrefix
$config.'target.vcsa'.network.gateway = $VMGateway
$config.'target.vcsa'.network.hostname = $VCSAHostname
$config.'target.vcsa'.os.password = $VCSARootPassword
if($VCSASSHEnable -eq "true") {
$VCSASSHEnableVar = $true
} else {
$VCSASSHEnableVar = $false
}
$config.'target.vcsa'.os.'ssh.enable' = $VCSASSHEnableVar
$config.'target.vcsa'.sso.password = $VCSASSOPassword
$config.'target.vcsa'.sso.'domain-name' = $VCSASSODomainName
$config.'target.vcsa'.sso.'site-name' = $VCSASSOSiteName
My-Logger "Creating VCSA JSON Configuration file for deployment ..."
$config | ConvertTo-Json | Set-Content -Path "$($ENV:Temp)\jsontemplate.json"
My-Logger "Deploying the VCSA ..."
$output = Invoke-Expression "$($VCSAInstallerPath)\vcsa-cli-installer\win32\vcsa-deploy.exe install --no-esx-ssl-verify --accept-eula $($ENV:Temp)\jsontemplate.json" -ErrorVariable vcsaDeployOutput 2>&1
$vcsaDeployOutput | Out-File -Append -LiteralPath $verboseLogFile
} else {
$config = (Get-Content -Raw "$($VCSAInstallerPath)\vcsa-cli-installer\templates\install\embedded_vCSA_on_VC.json") | convertfrom-json
$config.'target.vcsa'.vc.hostname = $VIServer
$config.'target.vcsa'.vc.username = $VIUsername
$config.'target.vcsa'.vc.password = $VIPassword
$config.'target.vcsa'.vc.datastore = $datastore
$config.'target.vcsa'.vc.datacenter = $datacenter.name
$config.'target.vcsa'.vc.target = $VMCluster
$config.'target.vcsa'.appliance.'deployment.network' = $VMNetwork
$config.'target.vcsa'.appliance.'thin.disk.mode' = $true
$config.'target.vcsa'.appliance.'deployment.option' = $VCSADeploymentSize
$config.'target.vcsa'.appliance.name = $VCSADisplayName
$config.'target.vcsa'.network.'ip.family' = "ipv4"
$config.'target.vcsa'.network.mode = "static"
$config.'target.vcsa'.network.ip = $VCSAIPAddress
$config.'target.vcsa'.network.'dns.servers'[0] = $VMDNS
$config.'target.vcsa'.network.'dns.servers'[1] = $null
$config.'target.vcsa'.network.prefix = $VCSAPrefix
$config.'target.vcsa'.network.gateway = $VMGateway
$config.'target.vcsa'.network.hostname = $VCSAHostname
$config.'target.vcsa'.os.password = $VCSARootPassword
if($VCSASSHEnable -eq "true") {
$VCSASSHEnableVar = $true
} else {
$VCSASSHEnableVar = $false
}
$config.'target.vcsa'.os.'ssh.enable' = $VCSASSHEnableVar
$config.'target.vcsa'.sso.password = $VCSASSOPassword
$config.'target.vcsa'.sso.'domain-name' = $VCSASSODomainName
$config.'target.vcsa'.sso.'site-name' = $VCSASSOSiteName
My-Logger "Creating VCSA JSON Configuration file for deployment ..."
$config | ConvertTo-Json | Set-Content -Path "$($ENV:Temp)\jsontemplate.json"
My-Logger "Deploying the VCSA ..."
$output = Invoke-Expression "$($VCSAInstallerPath)\vcsa-cli-installer\win32\vcsa-deploy.exe install --no-esx-ssl-verify --accept-eula $($ENV:Temp)\jsontemplate.json" -ErrorVariable vcsaDeployOutput 2>&1
$vcsaDeployOutput | Out-File -Append -LiteralPath $verboseLogFile
}
}
if($moveVMsIntovApp -eq 1 -and $DeploymentTarget -eq "VCENTER") {
My-Logger "Creating vApp $VAppName ..."
$VApp = New-VApp -Name $VAppName -Server $viConnection -Location $cluster
if($deployNestedESXiVMs -eq 1) {
My-Logger "Moving Nested ESXi VMs into $VAppName vApp ..."
$NestedESXiHostnameToIPs.GetEnumerator() | Sort-Object -Property Value | Foreach-Object {
$vm = Get-VM -Name $_.Key -Server $viConnection
Move-VM -VM $vm -Server $viConnection -Destination $VApp -Confirm:$false | Out-File -Append -LiteralPath $verboseLogFile
}
}
if($deployVCSA -eq 1) {
$vcsaVM = Get-VM -Name $VCSADisplayName
My-Logger "Moving $vcsaVM into $VAppName vApp ..."
Move-VM -VM $vcsaVM -Server $viConnection -Destination $VApp -Confirm:$false | Out-File -Append -LiteralPath $verboseLogFile
}
}
My-Logger "Disconnecting from $VIServer ..."
Disconnect-VIServer $viConnection -Confirm:$false
if($setupNewVC -eq 1) {
My-Logger "Connecting to the new VCSA ..."
$vc = Connect-VIServer $VCSAIPAddress -User "administrator@$VCSASSODomainName" -Password $VCSASSOPassword -WarningAction SilentlyContinue
My-Logger "Creating Datacenter $NewVCDatacenterName ..."
New-Datacenter -Server $vc -Name $NewVCDatacenterName -Location (Get-Folder -Type Datacenter -Server $vc) | Out-File -Append -LiteralPath $verboseLogFile
My-Logger "Creating VSAN Cluster $NewVCVSANClusterName ..."
New-Cluster -Server $vc -Name $NewVCVSANClusterName -Location (Get-Datacenter -Name $NewVCDatacenterName -Server $vc) -DrsEnabled -VsanEnabled -VsanDiskClaimMode 'Manual' | Out-File -Append -LiteralPath $verboseLogFile
if($addESXiHostsToVC -eq 1) {
$NestedESXiHostnameToIPs.GetEnumerator() | Sort-Object -Property Value | Foreach-Object {
$VMName = $_.Key
$VMIPAddress = $_.Value
My-Logger "Adding ESXi host $VMIPAddress to Cluster ..."
Add-VMHost -Server $vc -Location (Get-Cluster -Name $NewVCVSANClusterName) -User "root" -Password $VMPassword -Name $VMIPAddress -Force | Out-File -Append -LiteralPath $verboseLogFile
}
}
if($configureVSANDiskGroups -eq 1) {
# New vSAN cmdlets only works on 6.0u3+
$VmhostToCheckVersion = (Get-Cluster -Server $vc | Get-VMHost)[0]
$MajorVersion = $VmhostToCheckVersion.Version
$UpdateVersion = (Get-AdvancedSetting -Entity $VmhostToCheckVersion -Name Misc.HostAgentUpdateLevel).value
if( ($MajorVersion -eq "6.0.0" -and $UpdateVersion -eq "3") -or $MajorVersion -eq "6.5.0") {
My-Logger "Enabling VSAN Space Efficiency/De-Dupe & disabling VSAN Health Check ..."
Get-VsanClusterConfiguration -Server $vc -Cluster $NewVCVSANClusterName | Set-VsanClusterConfiguration -SpaceEfficiencyEnabled $true -HealthCheckIntervalMinutes 0 | Out-File -Append -LiteralPath $verboseLogFile
}
foreach ($vmhost in Get-Cluster -Server $vc | Get-VMHost) {
$luns = $vmhost | Get-ScsiLun | select CanonicalName, CapacityGB
My-Logger "Querying ESXi host disks to create VSAN Diskgroups ..."
foreach ($lun in $luns) {
if(([int]($lun.CapacityGB)).toString() -eq "$NestedESXiCachingvDisk") {
$vsanCacheDisk = $lun.CanonicalName
}
if(([int]($lun.CapacityGB)).toString() -eq "$NestedESXiCapacityvDisk") {
$vsanCapacityDisk = $lun.CanonicalName
}
}
My-Logger "Creating VSAN DiskGroup for $vmhost ..."
New-VsanDiskGroup -Server $vc -VMHost $vmhost -SsdCanonicalName $vsanCacheDisk -DataDiskCanonicalName $vsanCapacityDisk | Out-File -Append -LiteralPath $verboseLogFile
}
}
if($clearVSANHealthCheckAlarm -eq 1) {
My-Logger "Clearing default VSAN Health Check Alarms, not applicable in Nested ESXi env ..."
$alarmMgr = Get-View AlarmManager -Server $vc
Get-Cluster -Server $vc | where {$_.ExtensionData.TriggeredAlarmState} | %{
$cluster = $_
$Cluster.ExtensionData.TriggeredAlarmState | %{
$alarmMgr.AcknowledgeAlarm($_.Alarm,$cluster.ExtensionData.MoRef)
}
}
}
My-Logger "Disconnecting from new VCSA ..."
Disconnect-VIServer $vc -Confirm:$false
}
$EndTime = Get-Date
$duration = [math]::Round((New-TimeSpan -Start $StartTime -End $EndTime).TotalMinutes,2)
My-Logger "vSphere $vSphereVersion Lab Deployment Complete!"
My-Logger "StartTime: $StartTime"
My-Logger " EndTime: $EndTime"
My-Logger " Duration: $duration minutes"