-
Notifications
You must be signed in to change notification settings - Fork 132
/
vsphere-6.5-standard-lab-deployment.ps1
930 lines (811 loc) · 44.4 KB
/
vsphere-6.5-standard-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
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
# Author: William Lam
# Website: www.virtuallyghetto.com
# Description: PowerCLI script to deploy a fully functional vSphere 6.5 lab consisting of 3
# Nested ESXi hosts enable w/vSAN + VCSA 6.5. 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)
# 02/21/17
# * Support for deploying NSX 6.3 & registering with vCenter Server
# * Support for updating Nested ESXi VM to ESXi 6.5a (required for NSX 6.3)
# * Support for VDS + VXLAN VMkernel configuration (required for NSX 6.3)
# * Support for "Private" Portgroup on eth1 for Nested ESXi VM used for VXLAN traffic (required for NSX 6.3)
# * Support for both Virtual & Distributed Portgroup on $VMNetwork
# * Support for adding ESXi hosts into VC using DNS name (disabled by default)
# * Added CPU/MEM/Storage resource requirements in confirmation screen
# 05/08/17
# * Support for patching ESXi using VMware Online repo thanks to Matt Lichstein for contribution
# * Added fix to test ESXi endpoint before trying to patch
# Physical ESXi host or vCenter Server to deploy vSphere 6.5 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.5 VA + extracted VCSA 6.5 ISO
$NestedESXiApplianceOVA = "C:\Users\primp\Desktop\Nested_ESXi6.5_Appliance_Template_v1.ova"
$VCSAInstallerPath = "C:\Users\primp\Desktop\VMware-VCSA-all-6.5.0-4944578"
$NSXOVA = "C:\Users\primp\Desktop\VMware-NSX-Manager-6.3.0-5007049.ova"
$ESXi65OfflineBundle = "C:\Users\primp\Desktop\ESXi650-201701001\vmw-ESXi-6.5.0-metadata.zip" # Used for offline upgrade only
$ESXiProfileName = "ESXi-6.5.0-20170404001-standard" # Used for online upgrade only
# Nested ESXi VMs to deploy
$NestedESXiHostnameToIPs = @{
"vesxi65-1" = "172.30.0.171"
"vesxi65-2" = "172.30.0.172"
"vesxi65-3" = "172.30.0.173"
}
# Nested ESXi VM Resources
$NestedESXivCPU = "2"
$NestedESXivMEM = "6" #GB
$NestedESXiCachingvDisk = "4" #GB
$NestedESXiCapacityvDisk = "8" #GB
# VCSA Deployment Configuration
$VCSADeploymentSize = "tiny"
$VCSADisplayName = "vcenter65-1"
$VCSAIPAddress = "172.30.0.170"
$VCSAHostname = "vcenter65-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 Nested ESXi, VCSA & NSX VMs
$VirtualSwitchType = "VDS" # VSS or VDS
$VMNetwork = "dv-access333-dev"
$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.170"
# 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"
# NSX Manager Configuration
$DeployNSX = 0
$NSXvCPU = "2" # Reconfigure NSX vCPU
$NSXvMEM = "8" # Reconfigure NSX vMEM (GB)
$NSXDisplayName = "nsx63-1"
$NSXHostname = "nsx63-1.primp-industries.com"
$NSXIPAddress = "172.30.0.250"
$NSXNetmask = "255.255.255.0"
$NSXGateway = "172.30.0.1"
$NSXSSHEnable = "true"
$NSXCEIPEnable = "false"
$NSXUIPassword = "VMw@re123!"
$NSXCLIPassword = "VMw@re123!"
# VDS / VXLAN Configurations
$PrivateVXLANVMNetwork = "dv-private-network" # Existing Portgroup
$VDSName = "VDS-6.5"
$VXLANDVPortgroup = "VXLAN"
$VXLANSubnet = "172.16.66."
$VXLANNetmask = "255.255.255.0"
# Advanced Configurations
# Set to 1 only if you have DNS (forward/reverse) for ESXi hostnames
$addHostByDnsName = 0
# Upgrade vESXi hosts (defaults to pulling upgrade from VMware using profile specified in $ESXiProfileName)
$upgradeESXi = 0
# Set to 1 only if you want to upgrade using local bundle specified in $ESXi65OfflineBundle
$offlineUpgrade = 0
#### DO NOT EDIT BEYOND HERE ####
$verboseLogFile = "vsphere65-lab-deployment.log"
$vSphereVersion = "6.5"
$deploymentType = "Standard"
$random_string = -join ((65..90) + (97..122) | Get-Random -Count 8 | % {[char]$_})
$VAppName = "Nested-vSphere-Lab-$vSphereVersion-$random_string"
$depotServer = "https://hostupdate.vmware.com/software/VUM/PRODUCTION/main/vmw-depot-index.xml"
$vcsaSize2MemoryStorageMap = @{
"tiny"=@{"cpu"="2";"mem"="10";"disk"="250"};
"small"=@{"cpu"="4";"mem"="16";"disk"="290"};
"medium"=@{"cpu"="8";"mem"="24";"disk"="425"};
"large"=@{"cpu"="16";"mem"="32";"disk"="640"};
"xlarge"=@{"cpu"="24";"mem"="48";"disk"="980"}
}
$esxiTotalCPU = 0
$vcsaTotalCPU = 0
$nsxTotalCPU = 0
$esxiTotalMemory = 0
$vcsaTotalMemory = 0
$nsxTotalMemory = 0
$esxiTotStorage = 0
$vcsaTotalStorage = 0
$nsxTotalStorage = 0
$preCheck = 1
$confirmDeployment = 1
$deployNestedESXiVMs = 1
$deployVCSA = 1
$setupNewVC = 1
$addESXiHostsToVC = 1
$configureVSANDiskGroups = 1
$clearVSANHealthCheckAlarm = 1
$setupVXLAN = 1
$configureNSX = 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
}
Function URL-Check([string] $url) {
$isWorking = $true
try {
$request = [System.Net.WebRequest]::Create($url)
$request.Method = "HEAD"
$request.UseDefaultCredentials = $true
$response = $request.GetResponse()
$httpStatus = $response.StatusCode
$isWorking = ($httpStatus -eq "OK")
}
catch {
$isWorking = $false
}
return $isWorking
}
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($DeployNSX -eq 1) {
if(!(Test-Path $NSXOVA)) {
Write-Host -ForegroundColor Red "`nUnable to find $NSXOVA ...`nexiting"
exit
}
if(-not (Get-Module -Name "PowerNSX")) {
Write-Host -ForegroundColor Red "`nPowerNSX Module is not loaded, please install and load PowerNSX before running script ...`nexiting"
exit
}
$upgradeESXi = 1
}
if($upgradeESXi -eq 1) {
if($offlineUpgrade -eq 1) {
if(!(Test-Path $ESXi65OfflineBundle)) {
Write-Host -ForegroundColor Red "`nUnable to find $ESXi65OfflineBundle ...`nexiting"
exit
}
else {
if(!(URL-Check($depotServer))) {
Write-Host -ForegroundColor Red "`nVMware depot server is unavailable ...`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 Target: "
Write-Host -ForegroundColor White $DeploymentTarget
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($DeployNSX -eq 1) {
Write-Host -NoNewline -ForegroundColor Green "NSX Image Path: "
Write-Host -ForegroundColor White $NSXOVA
}
if($DeploymentTarget -eq "ESXI") {
Write-Host -ForegroundColor Yellow "`n---- Physical ESXi Deployment Target Configuration ----"
Write-Host -NoNewline -ForegroundColor Green "ESXi Address: "
} else {
Write-Host -ForegroundColor Yellow "`n---- vCenter Server Deployment Target 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
if($DeployNSX -eq 1 -and $setupVXLAN -eq 1) {
Write-Host -NoNewline -ForegroundColor Green "Private VXLAN VM Network: "
Write-Host -ForegroundColor White $PrivateVXLANVMNetwork
}
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
if($DeployNSX -eq 1 -and $setupVXLAN -eq 1) {
Write-Host -NoNewline -ForegroundColor Green "VDS Name: "
Write-Host -ForegroundColor White $VDSName
Write-Host -NoNewline -ForegroundColor Green "VXLAN Portgroup Name: "
Write-Host -ForegroundColor White $VXLANDVPortgroup
Write-Host -NoNewline -ForegroundColor Green "VXLAN Subnet: "
Write-Host -ForegroundColor White $VXLANSubnet
Write-Host -NoNewline -ForegroundColor Green "VXLAN Netmask: "
Write-Host -ForegroundColor White $VXLANNetmask
}
if($DeployNSX -eq 1) {
Write-Host -ForegroundColor Yellow "`n---- NSX Configuration ----"
Write-Host -NoNewline -ForegroundColor Green "vCPU: "
Write-Host -ForegroundColor White $NSXvCPU
Write-Host -NoNewline -ForegroundColor Green "Memory (GB): "
Write-Host -ForegroundColor White $NSXvMEM
Write-Host -NoNewline -ForegroundColor Green "Hostname: "
Write-Host -ForegroundColor White $NSXHostname
Write-Host -NoNewline -ForegroundColor Green "IP Address: "
Write-Host -ForegroundColor White $NSXIPAddress
Write-Host -NoNewline -ForegroundColor Green "Netmask: "
Write-Host -ForegroundColor White $NSXNetmask
Write-Host -NoNewline -ForegroundColor Green "Gateway: "
Write-Host -ForegroundColor White $NSXGateway
Write-Host -NoNewline -ForegroundColor Green "Enable SSH: "
Write-Host -ForegroundColor White $NSXSSHEnable
Write-Host -NoNewline -ForegroundColor Green "Enable CEIP: "
Write-Host -ForegroundColor White $NSXCEIPEnable
Write-Host -NoNewline -ForegroundColor Green "UI Password: "
Write-Host -ForegroundColor White $NSXUIPassword
Write-Host -NoNewline -ForegroundColor Green "CLI Password: "
Write-Host -ForegroundColor White $NSXCLIPassword
}
$esxiTotalCPU = $NestedESXiHostnameToIPs.count * [int]$NestedESXivCPU
$esxiTotalMemory = $NestedESXiHostnameToIPs.count * [int]$NestedESXivMEM
$esxiTotalStorage = ($NestedESXiHostnameToIPs.count * [int]$NestedESXiCachingvDisk) + ($NestedESXiHostnameToIPs.count * [int]$NestedESXiCapacityvDisk)
$vcsaTotalCPU = $vcsaSize2MemoryStorageMap.$VCSADeploymentSize.cpu
$vcsaTotalMemory = $vcsaSize2MemoryStorageMap.$VCSADeploymentSize.mem
$vcsaTotalStorage = $vcsaSize2MemoryStorageMap.$VCSADeploymentSize.disk
Write-Host -ForegroundColor Yellow "`n---- Resource Requirements ----"
Write-Host -NoNewline -ForegroundColor Green "ESXi VM CPU: "
Write-Host -NoNewline -ForegroundColor White $esxiTotalCPU
Write-Host -NoNewline -ForegroundColor Green " ESXi VM Memory: "
Write-Host -NoNewline -ForegroundColor White $esxiTotalMemory "GB "
Write-Host -NoNewline -ForegroundColor Green "ESXi VM Storage: "
Write-Host -ForegroundColor White $esxiTotalStorage "GB"
Write-Host -NoNewline -ForegroundColor Green "VCSA VM CPU: "
Write-Host -NoNewline -ForegroundColor White $vcsaTotalCPU
Write-Host -NoNewline -ForegroundColor Green " VCSA VM Memory: "
Write-Host -NoNewline -ForegroundColor White $vcsaTotalMemory "GB "
Write-Host -NoNewline -ForegroundColor Green "VCSA VM Storage: "
Write-Host -ForegroundColor White $vcsaTotalStorage "GB"
if($DeployNSX -eq 1) {
$nsxTotalCPU = [int]$NSXvCPU
$nsxTotalMemory = [int]$NSXvMEM
$nsxTotalStorage = 60
Write-Host -NoNewline -ForegroundColor Green "NSX VM CPU: "
Write-Host -NoNewline -ForegroundColor White $nsxTotalCPU
Write-Host -NoNewline -ForegroundColor Green " NSX VM Memory: "
Write-Host -NoNewline -ForegroundColor White $nsxTotalMemory "GB "
Write-Host -NoNewline -ForegroundColor Green " NSX VM Storage: "
Write-Host -ForegroundColor White $nsxTotalStorage "GB"
}
Write-Host -ForegroundColor White "---------------------------------------------"
Write-Host -NoNewline -ForegroundColor Green "Total CPU: "
Write-Host -ForegroundColor White ($esxiTotalCPU + $vcsaTotalCPU + $nsxTotalCPU)
Write-Host -NoNewline -ForegroundColor Green "Total Memory: "
Write-Host -ForegroundColor White ($esxiTotalMemory + $vcsaTotalMemory + $nsxTotalMemory) "GB"
Write-Host -NoNewline -ForegroundColor Green "Total Storage: "
Write-Host -ForegroundColor White ($esxiTotalStorage + $vcsaTotalStorage + $nsxTotalStorage) "GB"
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
if($VirtualSwitchType -eq "VSS") {
$network = Get-VirtualPortGroup -Server $viConnection -Name $VMNetwork
if($DeployNSX -eq 1) {
$privateNetwork = Get-VirtualPortGroup -Server $viConnection -Name $PrivateVXLANVMNetwork
}
} else {
$network = Get-VDPortgroup -Server $viConnection -Name $VMNetwork
if($DeployNSX -eq 1) {
$privateNetwork = Get-VDPortgroup -Server $viConnection -Name $PrivateVXLANVMNetwork
}
}
$vmhost = Get-VMHost -Server $viConnection
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
if($VirtualSwitchType -eq "VSS") {
$network = Get-VirtualPortGroup -Server $viConnection -Name $VMNetwork | Select -First 1
if($DeployNSX -eq 1) {
$privateNetwork = Get-VirtualPortGroup -Server $viConnection -Name $PrivateVXLANVMNetwork | Select -First 1
}
} else {
$network = Get-VDPortgroup -Server $viConnection -Name $VMNetwork | Select -First 1
if($DeployNSX -eq 1) {
$privateNetwork = Get-VDPortgroup -Server $viConnection -Name $PrivateVXLANVMNetwork | Select -First 1
}
}
$cluster = Get-Cluster -Server $viConnection -Name $VMCluster
$datacenter = $cluster | Get-Datacenter
$vmhost = $cluster | Get-VMHost | Select -First 1
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
}
}
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
# Add the dvfilter settings to the exisiting ethernet1 (not part of ova template)
My-Logger "Correcting missing dvFilter settings for Eth1 ..."
$vm | New-AdvancedSetting -name "ethernet1.filter4.name" -value "dvfilter-maclearn" -confirm:$false -ErrorAction SilentlyContinue | Out-File -Append -LiteralPath $verboseLogFile
$vm | New-AdvancedSetting -Name "ethernet1.filter4.onFailure" -value "failOpen" -confirm:$false -ErrorAction SilentlyContinue | Out-File -Append -LiteralPath $verboseLogFile
My-Logger "Updating VM Network ..."
$vm | Get-NetworkAdapter -Name "Network adapter 1" | Set-NetworkAdapter -Portgroup $network -confirm:$false | Out-File -Append -LiteralPath $verboseLogFile
sleep 5
if($DeployNSX -eq 1) {
$vm | Get-NetworkAdapter -Name "Network adapter 2" | Set-NetworkAdapter -Portgroup $privateNetwork -confirm:$false | Out-File -Append -LiteralPath $verboseLogFile
} else {
$vm | Get-NetworkAdapter -Name "Network adapter 2" | Set-NetworkAdapter -Portgroup $network -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
$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 Eth1 ..."
$vm | New-AdvancedSetting -name "ethernet1.filter4.name" -value "dvfilter-maclearn" -confirm:$false -ErrorAction SilentlyContinue | Out-File -Append -LiteralPath $verboseLogFile
$vm | New-AdvancedSetting -Name "ethernet1.filter4.onFailure" -value "failOpen" -confirm:$false -ErrorAction SilentlyContinue | Out-File -Append -LiteralPath $verboseLogFile
if($DeployNSX -eq 1) {
My-Logger "Connecting Eth1 to $privateNetwork ..."
$vm | Get-NetworkAdapter -Name "Network adapter 2" | Set-NetworkAdapter -Portgroup $privateNetwork -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($DeployNSX -eq 1) {
if($DeploymentTarget -eq "VCENTER") {
$ovfconfig = Get-OvfConfiguration $NSXOVA
$ovfconfig.NetworkMapping.VSMgmt.value = $VMNetwork
$ovfconfig.common.vsm_hostname.value = $NSXHostname
$ovfconfig.common.vsm_ip_0.value = $NSXIPAddress
$ovfconfig.common.vsm_netmask_0.value = $NSXNetmask
$ovfconfig.common.vsm_gateway_0.value = $NSXGateway
$ovfconfig.common.vsm_dns1_0.value = $VMDNS
$ovfconfig.common.vsm_domain_0.value = $VMDomain
$ovfconfig.common.vsm_ntp_0 = $VMNTP
if($NSXSSHEnable -eq "true") {
$NSXSSHEnableVar = $true
} else {
$NSXSSHEnableVar = $false
}
$ovfconfig.common.vsm_isSSHEnabled.value = $NSXSSHEnableVar
if($NSXCEIPEnable -eq "true") {
$NSXCEIPEnableVar = $true
} else {
$NSXCEIPEnableVar = $false
}
$ovfconfig.common.vsm_isCEIPEnabled.value = $NSXCEIPEnableVar
$ovfconfig.common.vsm_cli_passwd_0.value = $NSXUIPassword
$ovfconfig.common.vsm_cli_en_passwd_0.value = $NSXCLIPassword
My-Logger "Deploying NSX VM $NSXDisplayName ..."
$vm = Import-VApp -Source $NSXOVA -OvfConfiguration $ovfconfig -Name $NSXDisplayName -Location $cluster -VMHost $vmhost -Datastore $datastore -DiskStorageFormat thin
My-Logger "Updating vCPU Count to $NSXvCPU & vMEM to $NSXvMEM GB ..."
Set-VM -Server $viConnection -VM $vm -NumCpu $NSXvCPU -MemoryGB $NSXvMEM -Confirm:$false | Out-File -Append -LiteralPath $verboseLogFile
My-Logger "Powering On $NSXDisplayName ..."
$vm | Start-Vm -RunAsync | Out-Null
}
}
if($upgradeESXi -eq 1) {
sleep 60
$NestedESXiHostnameToIPs.GetEnumerator() | Sort-Object -Property Value | Foreach-Object {
$VMName = $_.Key
$VMIPAddress = $_.Value
My-Logger "Connecting directly to $VMName for ESXi upgrade ..."
while(1) {
try {
$results = Invoke-WebRequest -Uri https://$VMIPAddress/ui -Method GET
if($results.StatusCode -eq 200) {
break
}
}
catch {
My-Logger "$VMName is not ready yet, sleeping 30seconds ..."
sleep 30
}
}
# This is apparently needed due to patching using online image profile taking longer
Set-PowerCLIConfiguration -WebOperationTimeoutSeconds 900 -Scope Session -Confirm:$false | Out-Null
$vESXi = Connect-VIServer -Server $VMIPAddress -User root -Password $VMPassword -WarningAction SilentlyContinue
My-Logger "Entering Maintenance Mode ..."
Set-VMHost -VMhost $VMIPAddress -State Maintenance -Confirm:$false | Out-File -Append -LiteralPath $verboseLogFile
if($offlineUpgrade -eq 1) {
My-Logger "Upgrading $VMname using offline bundle $ESXi65OfflineBundle ..."
Install-VMHostPatch -VMHost $VMIPAddress -LocalPath $ESXi65OfflineBundle -HostUsername root -HostPassword $VMPassword -WarningAction SilentlyContinue -Confirm:$false | Out-File -Append -LiteralPath $verboseLogFile
}
else {
My-Logger "Upgrading $VMName using Image Profile $ESXiProfileName ..."
$esxcli = Get-EsxCli -VMHost $VMIPAddress -V2
$esxcli.network.firewall.ruleset.set.Invoke(@{enabled = 'true' ; rulesetid = 'httpClient'}) | Out-Null
$esxcli.software.profile.update.Invoke(@{profile = $ESXiProfileName; depot = $depotServer}) | Out-File -Append -LiteralPath $verboseLogFile
}
My-Logger "Rebooting $VMName ..."
Restart-VMHost $VMIPAddress -RunAsync -Confirm:$false | Out-File -Append -LiteralPath $verboseLogFile
My-Logger "Disconnecting from new ESXi host ..."
Disconnect-VIServer $vESXi -Confirm:$false
}
}
if($deployVCSA -eq 1) {
if($DeploymentTarget -eq "ESXI") {
# Deploy using the VCSA CLI Installer
$config = (Get-Content -Raw "$($VCSAInstallerPath)\vcsa-cli-installer\templates\install\embedded_vCSA_on_ESXi.json") | convertfrom-json
$config.'new.vcsa'.esxi.hostname = $VIServer
$config.'new.vcsa'.esxi.username = $VIUsername
$config.'new.vcsa'.esxi.password = $VIPassword
$config.'new.vcsa'.esxi.'deployment.network' = $VMNetwork
$config.'new.vcsa'.esxi.datastore = $datastore
$config.'new.vcsa'.appliance.'thin.disk.mode' = $true
$config.'new.vcsa'.appliance.'deployment.option' = $VCSADeploymentSize
$config.'new.vcsa'.appliance.name = $VCSADisplayName
$config.'new.vcsa'.network.'ip.family' = "ipv4"
$config.'new.vcsa'.network.mode = "static"
$config.'new.vcsa'.network.ip = $VCSAIPAddress
$config.'new.vcsa'.network.'dns.servers'[0] = $VMDNS
$config.'new.vcsa'.network.prefix = $VCSAPrefix
$config.'new.vcsa'.network.gateway = $VMGateway
$config.'new.vcsa'.network.'system.name' = $VCSAHostname
$config.'new.vcsa'.os.password = $VCSARootPassword
if($VCSASSHEnable -eq "true") {
$VCSASSHEnableVar = $true
} else {
$VCSASSHEnableVar = $false
}
$config.'new.vcsa'.os.'ssh.enable' = $VCSASSHEnableVar
$config.'new.vcsa'.sso.password = $VCSASSOPassword
$config.'new.vcsa'.sso.'domain-name' = $VCSASSODomainName
$config.'new.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 ..."
Invoke-Expression "$($VCSAInstallerPath)\vcsa-cli-installer\win32\vcsa-deploy.exe install --no-esx-ssl-verify --accept-eula --acknowledge-ceip $($ENV:Temp)\jsontemplate.json"| Out-File -Append -LiteralPath $verboseLogFile
} else {
$config = (Get-Content -Raw "$($VCSAInstallerPath)\vcsa-cli-installer\templates\install\embedded_vCSA_on_VC.json") | convertfrom-json
$config.'new.vcsa'.vc.hostname = $VIServer
$config.'new.vcsa'.vc.username = $VIUsername
$config.'new.vcsa'.vc.password = $VIPassword
$config.'new.vcsa'.vc.'deployment.network' = $VMNetwork
$config.'new.vcsa'.vc.datastore = $datastore
$config.'new.vcsa'.vc.datacenter = $datacenter.name
$config.'new.vcsa'.vc.target = $VMCluster
$config.'new.vcsa'.appliance.'thin.disk.mode' = $true
$config.'new.vcsa'.appliance.'deployment.option' = $VCSADeploymentSize
$config.'new.vcsa'.appliance.name = $VCSADisplayName
$config.'new.vcsa'.network.'ip.family' = "ipv4"
$config.'new.vcsa'.network.mode = "static"
$config.'new.vcsa'.network.ip = $VCSAIPAddress
$config.'new.vcsa'.network.'dns.servers'[0] = $VMDNS
$config.'new.vcsa'.network.prefix = $VCSAPrefix
$config.'new.vcsa'.network.gateway = $VMGateway
$config.'new.vcsa'.network.'system.name' = $VCSAHostname
$config.'new.vcsa'.os.password = $VCSARootPassword
if($VCSASSHEnable -eq "true") {
$VCSASSHEnableVar = $true
} else {
$VCSASSHEnableVar = $false
}
$config.'new.vcsa'.os.'ssh.enable' = $VCSASSHEnableVar
$config.'new.vcsa'.sso.password = $VCSASSOPassword
$config.'new.vcsa'.sso.'domain-name' = $VCSASSODomainName
$config.'new.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 ..."
Invoke-Expression "$($VCSAInstallerPath)\vcsa-cli-installer\win32\vcsa-deploy.exe install --no-esx-ssl-verify --accept-eula --acknowledge-ceip $($ENV:Temp)\jsontemplate.json"| Out-File -Append -LiteralPath $verboseLogFile
}
}
if($moveVMsIntovApp -eq 1 -and $DeploymentTarget -eq "VCENTER") {
# Check whether DRS is enabled as that is required to create vApp
if((Get-Cluster -Server $viConnection $cluster).DrsEnabled) {
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 -Server $viConnection
My-Logger "Moving $VCSADisplayName into $VAppName vApp ..."
Move-VM -VM $vcsaVM -Server $viConnection -Destination $VApp -Confirm:$false | Out-File -Append -LiteralPath $verboseLogFile
}
if($DeployNSX -eq 1) {
$nsxVM = Get-VM -Name $NSXDisplayName -Server $viConnection
My-Logger "Moving $NSXDisplayName into $VAppName vApp ..."
Move-VM -VM $nsxVM -Server $viConnection -Destination $VApp -Confirm:$false | Out-File -Append -LiteralPath $verboseLogFile
}
} else {
My-Logger "vApp $VAppName will NOT be created as DRS is NOT enabled on vSphere Cluster ${cluster} ..."
}
}
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
$targetVMHost = $VMIPAddress
if($addHostByDnsName -eq 1) {
$targetVMHost = $VMName
}
My-Logger "Adding ESXi host $targetVMHost to Cluster ..."
Add-VMHost -Server $vc -Location (Get-Cluster -Name $NewVCVSANClusterName) -User "root" -Password $VMPassword -Name $targetVMHost -Force | Out-File -Append -LiteralPath $verboseLogFile
}
}
if($DeployNSX -eq 1 -and $setupVXLAN -eq 1) {
My-Logger "Creating VDS $VDSName ..."
$vds = New-VDSwitch -Server $vc -Name $VDSName -Location (Get-Datacenter -Name $NewVCDatacenterName)
My-Logger "Creating new VXLAN DVPortgroup $VXLANDVPortgroup ..."
$vxlanDVPG = New-VDPortgroup -Server $vc -Name $VXLANDVPortgroup -Vds $vds
$vmhosts = Get-Cluster -Server $vc -Name $NewVCVSANClusterName | Get-VMHost
foreach ($vmhost in $vmhosts) {
$vmhostname = $vmhost.name
My-Logger "Adding $vmhostname to VDS ..."
Add-VDSwitchVMHost -Server $vc -VDSwitch $vds -VMHost $vmhost | Out-File -Append -LiteralPath $verboseLogFile
My-Logger "Adding vmmnic1 to VDS ..."
$vmnic = $vmhost | Get-VMHostNetworkAdapter -Physical -Name vmnic1
Add-VDSwitchPhysicalNetworkAdapter -Server $vc -DistributedSwitch $vds -VMHostPhysicalNic $vmnic -Confirm:$false | Out-File -Append -LiteralPath $verboseLogFile
$vmk0 = Get-VMHostNetworkAdapter -Server $vc -Name vmk0 -VMHost $vmhost
$lastNetworkOcet = $vmk0.ip.Split('.')[-1]
$vxlanVmkIP = $VXLANSubnet + $lastNetworkOcet
My-Logger "Adding VXLAN VMKernel $vxlanVmkIP to VDS ..."
New-VMHostNetworkAdapter -VMHost $vmhost -PortGroup $VXLANDVPortgroup -VirtualSwitch $vds -IP $vxlanVmkIP -SubnetMask $VXLANNetmask -Mtu 1600 | Out-File -Append -LiteralPath $verboseLogFile
}
}
if($configureVSANDiskGroups -eq 1) {
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)
}
}
}
# Exit maintanence mode in case patching was done earlier
foreach ($vmhost in Get-Cluster -Server $vc | Get-VMHost) {
if($vmhost.ConnectionState -eq "Maintenance") {
Set-VMHost -VMhost $vmhost -State Connected -RunAsync -Confirm:$false | Out-File -Append -LiteralPath $verboseLogFile
}
}
My-Logger "Disconnecting from new VCSA ..."
Disconnect-VIServer $vc -Confirm:$false
}
if($configureNSX -eq 1 -and $DeployNSX -eq 1 -and $setupVXLAN -eq 1) {
if(!(Connect-NSXServer -Server $NSXHostname -Username admin -Password $NSXUIPassword -DisableVIAutoConnect -WarningAction SilentlyContinue)) {
Write-Host -ForegroundColor Red "Unable to connect to NSX Manager, please check the deployment"
exit
} else {
My-Logger "Successfully logged into NSX Manager $NSXHostname ..."
}
$ssoUsername = "administrator@$VCSASSODomainName"
My-Logger "Registering NSX Manager with vCenter Server $VCSAHostname ..."
$vcConfig = Set-NsxManager -vCenterServer $VCSAHostname -vCenterUserName $ssoUsername -vCenterPassword $VCSASSOPassword
My-Logger "Registering NSX Manager with vCenter SSO $VCSAHostname ..."
$ssoConfig = Set-NsxManager -SsoServer $VCSAHostname -SsoUserName $ssoUsername -SsoPassword $VCSASSOPassword -AcceptAnyThumbprint
My-Logger "Disconnecting from NSX Manager ..."
Disconnect-NsxServer
}
$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"