-
Notifications
You must be signed in to change notification settings - Fork 0
/
vghetto-vsphere-with-kubernetes-external-nsxt-lab-deployment.ps1
1638 lines (1389 loc) · 78 KB
/
vghetto-vsphere-with-kubernetes-external-nsxt-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
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Author: William Lam
# Website: www.virtuallyghetto.com
# vCenter Server used to deploy vSphere with Kubernetes Lab
$VIServer = "mgmt-vcsa-01.cpbu.corp"
$VIUsername = "[email protected]"
$VIPassword = "VMware1!"
# Full Path to both the Nested ESXi 7.0 VA, Extracted VCSA 7.0 ISO & NSX-T OVAs
$NestedESXiApplianceOVA = "C:\Users\william\Desktop\Project-Pacific\Nested_ESXi7.0_Appliance_Template_v1.ova"
$VCSAInstallerPath = "C:\Users\william\Desktop\Project-Pacific\VMware-VCSA-all-7.0.0-15952498"
$NSXTManagerOVA = "C:\Users\william\Desktop\Project-Pacific\nsx-unified-appliance-3.0.0.0.0.15946739.ova"
$NSXTEdgeOVA = "C:\Users\william\Desktop\Project-Pacific\nsx-edge-3.0.0.0.0.15946012.ova"
# Nested ESXi VMs to deploy
$NestedESXiHostnameToIPs = @{
"pacific-esxi-7" = "172.17.31.113"
"pacific-esxi-8" = "172.17.31.114"
"pacific-esxi-9" = "172.17.31.115"
}
# Nested ESXi VM Resources
$NestedESXivCPU = "4"
$NestedESXivMEM = "24" #GB
$NestedESXiCachingvDisk = "8" #GB
$NestedESXiCapacityvDisk = "100" #GB
# VCSA Deployment Configuration
$VCSADeploymentSize = "tiny"
$VCSADisplayName = "pacific-vcsa-3"
$VCSAIPAddress = "172.17.31.112"
$VCSAHostname = "pacific-vcsa-3.cpbu.corp" #Change to IP if you don't have valid DNS
$VCSAPrefix = "24"
$VCSASSODomainName = "vsphere.local"
$VCSASSOPassword = "VMware1!"
$VCSARootPassword = "VMware1!"
$VCSASSHEnable = "true"
# General Deployment Configuration for Nested ESXi, VCSA & NSX VMs
$VMDatacenter = "San Jose"
$VMCluster = "Cluster-01"
$VMNetwork = "SJC-CORP-MGMT"
$VMDatastore = "vsanDatastore"
$VMNetmask = "255.255.255.0"
$VMGateway = "172.17.31.253"
$VMDNS = "172.17.31.5"
$VMNTP = "pool.ntp.org"
$VMPassword = "VMware1!"
$VMDomain = "cpbu.corp"
$VMSyslog = "172.17.31.112"
$VMFolder = "Project-Pacific"
# Applicable to Nested ESXi only
$VMSSH = "true"
$VMVMFS = "false"
# Name of new vSphere Datacenter/Cluster when VCSA is deployed
$NewVCDatacenterName = "Pacific-Datacenter"
$NewVCVSANClusterName = "Workload-Cluster"
$NewVCVDSName = "Pacific-VDS"
$NewVCDVPGName = "DVPG-Management Network"
# Pacific Configuration
$StoragePolicyName = "pacific-gold-storage-policy"
$StoragePolicyTagCategory = "pacific-demo-tag-category"
$StoragePolicyTagName = "pacific-demo-storage"
$DevOpsUsername = "devops"
$DevOpsPassword = "VMware1!"
# NSX-T Configuration
$NSXLicenseKey = ""
$NSXRootPassword = "VMware1!VMware1!"
$NSXAdminUsername = "admin"
$NSXAdminPassword = "VMware1!VMware1!"
$NSXAuditUsername = "audit"
$NSXAuditPassword = "VMware1!VMware1!"
$NSXSSHEnable = "true"
$NSXEnableRootLogin = "true"
$NSXVTEPNetwork = "Pacific-VTEP"
# Transport Node Profile
$TransportNodeProfileName = "Pacific-Host-Transport-Node-Profile"
# TEP IP Pool
$TunnelEndpointName = "TEP-IP-Pool"
$TunnelEndpointDescription = "Tunnel Endpoint for Transport Nodes"
$TunnelEndpointIPRangeStart = "172.30.1.10"
$TunnelEndpointIPRangeEnd = "172.30.1.20"
$TunnelEndpointCIDR = "172.30.1.0/24"
$TunnelEndpointGateway = "172.30.1.1"
# Transport Zones
$OverlayTransportZoneName = "TZ-Overlay"
$OverlayTransportZoneHostSwitchName = "nsxswitch"
$VlanTransportZoneName = "TZ-VLAN"
$VlanTransportZoneNameHostSwitchName = "edgeswitch"
# Network Segment
$NetworkSegmentName = "Pacific-Segment"
$NetworkSegmentVlan = "0"
# T0 Gateway
$T0GatewayName = "Pacific-T0-Gateway"
$T0GatewayInterfaceAddress = "172.17.31.119" # should be a routable address
$T0GatewayInterfacePrefix = "24"
$T0GatewayInterfaceStaticRouteName = "Pacific-Static-Route"
$T0GatewayInterfaceStaticRouteNetwork = "0.0.0.0/0"
$T0GatewayInterfaceStaticRouteAddress = "172.17.31.253"
# Uplink Profiles
$ESXiUplinkProfileName = "ESXi-Host-Uplink-Profile"
$ESXiUplinkProfilePolicy = "FAILOVER_ORDER"
$ESXiUplinkName = "uplink1"
$EdgeUplinkProfileName = "Edge-Uplink-Profile"
$EdgeUplinkProfilePolicy = "FAILOVER_ORDER"
$EdgeOverlayUplinkName = "uplink1"
$EdgeOverlayUplinkProfileActivepNIC = "fp-eth1"
$EdgeUplinkName = "tep-uplink"
$EdgeUplinkProfileActivepNIC = "fp-eth2"
$EdgeUplinkProfileTransportVLAN = "0"
$EdgeUplinkProfileMTU = "1600"
# Edge Cluster
$EdgeClusterName = "Edge-Cluster-01"
# NSX-T Manager Configurations
$NSXTMgrDeploymentSize = "small"
$NSXTMgrvCPU = "6" #override default size
$NSXTMgrvMEM = "24" #override default size
$NSXTMgrDisplayName = "pacific-nsx-3"
$NSXTMgrHostname = "pacific-nsx-3.cpbu.corp"
$NSXTMgrIPAddress = "172.17.31.118"
# NSX-T Edge Configuration
$NSXTEdgeDeploymentSize = "medium"
$NSXTEdgevCPU = "8" #override default size
$NSXTEdgevMEM = "32" #override default size
$NSXTEdgeHostnameToIPs = @{
"pacific-nsx-edge-3a" = "172.17.31.116"
}
# Advanced Configurations
# Set to 1 only if you have DNS (forward/reverse) for ESXi hostnames
$addHostByDnsName = 1
#### DO NOT EDIT BEYOND HERE ####
$debug = $true
$verboseLogFile = "pacific-nsxt-external-vghetto-lab-deployment.log"
$random_string = -join ((65..90) + (97..122) | Get-Random -Count 8 | % {[char]$_})
$VAppName = "vGhetto-Nested-Project-Pacific-NSX-T-External-Lab-$random_string"
$preCheck = 1
$confirmDeployment = 1
$deployNestedESXiVMs = 1
$deployVCSA = 1
$setupNewVC = 1
$addESXiHostsToVC = 1
$configureVSANDiskGroup = 1
$configureVDS = 1
$clearVSANHealthCheckAlarm = 1
$setupPacificStoragePolicy = 1
$deployNSXManager = 1
$deployNSXEdge = 1
$postDeployNSXConfig = 1
$setupPacific = 1
$moveVMsIntovApp = 1
$vcsaSize2MemoryStorageMap = @{
"tiny"=@{"cpu"="2";"mem"="12";"disk"="415"};
"small"=@{"cpu"="4";"mem"="19";"disk"="480"};
"medium"=@{"cpu"="8";"mem"="28";"disk"="700"};
"large"=@{"cpu"="16";"mem"="37";"disk"="1065"};
"xlarge"=@{"cpu"="24";"mem"="56";"disk"="1805"}
}
$nsxStorageMap = @{
"manager"="200";
"edge"="200"
}
$esxiTotalCPU = 0
$vcsaTotalCPU = 0
$nsxManagerTotalCPU = 0
$nsxEdgeTotalCPU = 0
$esxiTotalMemory = 0
$vcsaTotalMemory = 0
$nsxManagerTotalMemory = 0
$nsxEdgeTotalMemory = 0
$esxiTotalStorage = 0
$vcsaTotalStorage = 0
$nsxManagerTotalStorage = 0
$nsxEdgeTotalStorage = 0
$StartTime = Get-Date
Function Get-SSLThumbprint256 {
param(
[Parameter(
Position=0,
Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true)
]
[Alias('FullName')]
[String]$URL
)
$Code = @'
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
namespace CertificateCapture
{
public class Utility
{
public static Func<HttpRequestMessage,X509Certificate2,X509Chain,SslPolicyErrors,Boolean> ValidationCallback =
(message, cert, chain, errors) => {
var newCert = new X509Certificate2(cert);
var newChain = new X509Chain();
newChain.Build(newCert);
CapturedCertificates.Add(new CapturedCertificate(){
Certificate = newCert,
CertificateChain = newChain,
PolicyErrors = errors,
URI = message.RequestUri
});
return true;
};
public static List<CapturedCertificate> CapturedCertificates = new List<CapturedCertificate>();
}
public class CapturedCertificate
{
public X509Certificate2 Certificate { get; set; }
public X509Chain CertificateChain { get; set; }
public SslPolicyErrors PolicyErrors { get; set; }
public Uri URI { get; set; }
}
}
'@
if ($PSEdition -ne 'Core'){
Add-Type -AssemblyName System.Net.Http
if (-not ("CertificateCapture" -as [type])) {
Add-Type $Code -ReferencedAssemblies System.Net.Http
}
} else {
if (-not ("CertificateCapture" -as [type])) {
Add-Type $Code
}
}
$Certs = [CertificateCapture.Utility]::CapturedCertificates
$Handler = [System.Net.Http.HttpClientHandler]::new()
$Handler.ServerCertificateCustomValidationCallback = [CertificateCapture.Utility]::ValidationCallback
$Client = [System.Net.Http.HttpClient]::new($Handler)
$Result = $Client.GetAsync($Url).Result
$sha256 = [Security.Cryptography.SHA256]::Create()
$certBytes = $Certs[-1].Certificate.GetRawCertData()
$hash = $sha256.ComputeHash($certBytes)
$thumbprint = [BitConverter]::ToString($hash).Replace('-',':')
return $thumbprint
}
Function Set-VMKeystrokes {
<#
Please see http://www.virtuallyghetto.com/2017/09/automating-vm-keystrokes-using-the-vsphere-api-powercli.html for more details
#>
param(
[Parameter(Mandatory=$true)][String]$VMName,
[Parameter(Mandatory=$true)][String]$StringInput,
[Parameter(Mandatory=$false)][Boolean]$ReturnCarriage,
[Parameter(Mandatory=$false)][Boolean]$DebugOn
)
# Map subset of USB HID keyboard scancodes
# https://gist.github.com/MightyPork/6da26e382a7ad91b5496ee55fdc73db2
$hidCharacterMap = @{
"a"="0x04";
"b"="0x05";
"c"="0x06";
"d"="0x07";
"e"="0x08";
"f"="0x09";
"g"="0x0a";
"h"="0x0b";
"i"="0x0c";
"j"="0x0d";
"k"="0x0e";
"l"="0x0f";
"m"="0x10";
"n"="0x11";
"o"="0x12";
"p"="0x13";
"q"="0x14";
"r"="0x15";
"s"="0x16";
"t"="0x17";
"u"="0x18";
"v"="0x19";
"w"="0x1a";
"x"="0x1b";
"y"="0x1c";
"z"="0x1d";
"1"="0x1e";
"2"="0x1f";
"3"="0x20";
"4"="0x21";
"5"="0x22";
"6"="0x23";
"7"="0x24";
"8"="0x25";
"9"="0x26";
"0"="0x27";
"!"="0x1e";
"@"="0x1f";
"#"="0x20";
"$"="0x21";
"%"="0x22";
"^"="0x23";
"&"="0x24";
"*"="0x25";
"("="0x26";
")"="0x27";
"_"="0x2d";
"+"="0x2e";
"{"="0x2f";
"}"="0x30";
"|"="0x31";
":"="0x33";
"`""="0x34";
"~"="0x35";
"<"="0x36";
">"="0x37";
"?"="0x38";
"-"="0x2d";
"="="0x2e";
"["="0x2f";
"]"="0x30";
"\"="0x31";
"`;"="0x33";
"`'"="0x34";
","="0x36";
"."="0x37";
"/"="0x38";
" "="0x2c";
}
$vm = Get-View -ViewType VirtualMachine -Filter @{"Name"=$VMName}
# Verify we have a VM or fail
if(!$vm) {
Write-host "Unable to find VM $VMName"
return
}
$hidCodesEvents = @()
foreach($character in $StringInput.ToCharArray()) {
# Check to see if we've mapped the character to HID code
if($hidCharacterMap.ContainsKey([string]$character)) {
$hidCode = $hidCharacterMap[[string]$character]
$tmp = New-Object VMware.Vim.UsbScanCodeSpecKeyEvent
# Add leftShift modifer for capital letters and/or special characters
if( ($character -cmatch "[A-Z]") -or ($character -match "[!|@|#|$|%|^|&|(|)|_|+|{|}|||:|~|<|>|?]") ) {
$modifer = New-Object Vmware.Vim.UsbScanCodeSpecModifierType
$modifer.LeftShift = $true
$tmp.Modifiers = $modifer
}
# Convert to expected HID code format
$hidCodeHexToInt = [Convert]::ToInt64($hidCode,"16")
$hidCodeValue = ($hidCodeHexToInt -shl 16) -bor 0007
$tmp.UsbHidCode = $hidCodeValue
$hidCodesEvents+=$tmp
} else {
My-Logger Write-Host "The following character `"$character`" has not been mapped, you will need to manually process this character"
break
}
}
# Add return carriage to the end of the string input (useful for logins or executing commands)
if($ReturnCarriage) {
# Convert return carriage to HID code format
$hidCodeHexToInt = [Convert]::ToInt64("0x28","16")
$hidCodeValue = ($hidCodeHexToInt -shl 16) + 7
$tmp = New-Object VMware.Vim.UsbScanCodeSpecKeyEvent
$tmp.UsbHidCode = $hidCodeValue
$hidCodesEvents+=$tmp
}
# Call API to send keystrokes to VM
$spec = New-Object Vmware.Vim.UsbScanCodeSpec
$spec.KeyEvents = $hidCodesEvents
$results = $vm.PutUsbScanCodes($spec)
}
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 ...`n"
exit
}
if(!(Test-Path $VCSAInstallerPath)) {
Write-Host -ForegroundColor Red "`nUnable to find $VCSAInstallerPath ...`n"
exit
}
if(!(Test-Path $NSXTManagerOVA) -and $deployNSXManager -eq 1) {
Write-Host -ForegroundColor Red "`nUnable to find $NSXTManagerOVA ...`n"
exit
}
if(!(Test-Path $NSXTEdgeOVA) -and $deployNSXEdge -eq 1) {
Write-Host -ForegroundColor Red "`nUnable to find $NSXTEdgeOVA ...`n"
exit
}
if($PSVersionTable.PSEdition -ne "Core") {
Write-Host -ForegroundColor Red "`tPowerShell Core was not detected, please install that before continuing ... `n"
exit
}
# pre-check VTEP Network exists
$viConnection = Connect-VIServer $VIServer -User $VIUsername -Password $VIPassword -WarningAction SilentlyContinue
if(! (Get-VirtualNetwork $NSXVTEPNetwork -ErrorAction 'silentlycontinue')) {
Write-Host -ForegroundColor Red "`tUnable to locate $NSXVTEPNetwork portgroup, please create this network before continuing ... `n"
exit
}
Disconnect-VIServer $viConnection -Confirm:$false
if($NSXLicenseKey -eq "") {
Write-Host -ForegroundColor Red "`tNSX-T License is required, please fill out `$NSXLicenseKey variable...`n"
exit
}
}
if($confirmDeployment -eq 1) {
Write-Host -ForegroundColor Magenta "`nPlease confirm the following configuration will be deployed:`n"
Write-Host -ForegroundColor Yellow "---- vSphere with Kubernetes External NSX-T Automated Lab Deployment Configuration ---- "
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($deployNSXManager -eq 1) {
Write-Host -NoNewline -ForegroundColor Green "NSX-T Manager Image Path: "
Write-Host -ForegroundColor White $NSXTManagerOVA
}
if($deployNSXEdge -eq 1) {
Write-Host -NoNewline -ForegroundColor Green "NSX-T Edge Image Path: "
Write-Host -ForegroundColor White $NSXTEdgeOVA
}
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 "VM Network: "
Write-Host -ForegroundColor White $VMNetwork
if($deployNSXManager -eq 1 -or $deployNSXEdge -eq 1) {
Write-Host -NoNewline -ForegroundColor Green "NSX-T VTEP Network: "
Write-Host -ForegroundColor White $NSXVTEPNetwork
}
Write-Host -NoNewline -ForegroundColor Green "VM Storage: "
Write-Host -ForegroundColor White $VMDatastore
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 -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 "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($deployNSXManager -eq 1 -or $deployNSXEdge -eq 1) {
Write-Host -ForegroundColor Yellow "`n---- NSX-T Configuration ----"
Write-Host -NoNewline -ForegroundColor Green "NSX Manager Hostname: "
Write-Host -ForegroundColor White $NSXTMgrHostname
Write-Host -NoNewline -ForegroundColor Green "NSX Manager IP Address: "
Write-Host -ForegroundColor White $NSXTMgrIPAddress
if($deployNSXEdge -eq 1) {
Write-Host -NoNewline -ForegroundColor Green "# of NSX Edge VMs: "
Write-Host -ForegroundColor White $NSXTEdgeHostnameToIPs.count
Write-Host -NoNewline -ForegroundColor Green "IP Address(s): "
Write-Host -ForegroundColor White $NSXTEdgeHostnameToIPs.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 "Enable SSH: "
Write-Host -ForegroundColor White $NSXSSHEnable
Write-Host -NoNewline -ForegroundColor Green "Enable Root Login: "
Write-Host -ForegroundColor White $NSXEnableRootLogin
}
$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($deployNSXManager -eq 1 -or $deployNSXEdge -eq 1) {
if($deployNSXManager -eq 1) {
$nsxManagerTotalCPU += [int]$NSXTMgrvCPU
$nsxManagerTotalMemory += [int]$NSXTMgrvMEM
$nsxManagerTotalStorage += [int]$nsxStorageMap["manager"]
Write-Host -NoNewline -ForegroundColor Green "NSX-UA VM CPU: "
Write-Host -NoNewline -ForegroundColor White $nsxManagerTotalCPU
Write-Host -NoNewline -ForegroundColor Green " NSX-UA VM Memory: "
Write-Host -NoNewline -ForegroundColor White $nsxManagerTotalMemory "GB "
Write-Host -NoNewline -ForegroundColor Green " NSX-UA VM Storage: "
Write-Host -ForegroundColor White $nsxManagerTotalStorage "GB"
}
if($deployNSXEdge -eq 1) {
$nsxEdgeTotalCPU += $NSXTEdgeHostnameToIPs.count * [int]$NSXTEdgevCPU
$nsxEdgeTotalMemory += $NSXTEdgeHostnameToIPs.count * [int]$NSXTEdgevMEM
$nsxEdgeTotalStorage += $NSXTEdgeHostnameToIPs.count * [int]$nsxStorageMap["edge"]
Write-Host -NoNewline -ForegroundColor Green "NSX-Edge VM CPU: "
Write-Host -NoNewline -ForegroundColor White $nsxEdgeTotalCPU
Write-Host -NoNewline -ForegroundColor Green " NSX-Edge VM Memory: "
Write-Host -NoNewline -ForegroundColor White $nsxEdgeTotalMemory "GB "
Write-Host -NoNewline -ForegroundColor Green " NSX-Edge VM Storage: "
Write-Host -ForegroundColor White $nsxEdgeTotalStorage "GB"
}
}
Write-Host -ForegroundColor White "---------------------------------------------"
Write-Host -NoNewline -ForegroundColor Green "Total CPU: "
Write-Host -ForegroundColor White ($esxiTotalCPU + $vcsaTotalCPU + $nsxManagerTotalCPU + $nsxEdgeTotalCPU)
Write-Host -NoNewline -ForegroundColor Green "Total Memory: "
Write-Host -ForegroundColor White ($esxiTotalMemory + $vcsaTotalMemory + $nsxManagerTotalMemory + $nsxEdgeTotalMemory) "GB"
Write-Host -NoNewline -ForegroundColor Green "Total Storage: "
Write-Host -ForegroundColor White ($esxiTotalStorage + $vcsaTotalStorage + $nsxManagerTotalStorage + $nsxEdgeTotalStorage) "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
}
if( $deployNestedESXiVMs -eq 1 -or $deployVCSA -eq 1 -or $deployNSXManager -eq 1 -or $deployNSXEdge -eq 1) {
My-Logger "Connecting to Management vCenter Server $VIServer ..."
$viConnection = Connect-VIServer $VIServer -User $VIUsername -Password $VIPassword -WarningAction SilentlyContinue
$datastore = Get-Datastore -Server $viConnection -Name $VMDatastore | 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) {
$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
My-Logger "Adding vmnic2/vmnic3 to $NSXVTEPNetwork ..."
New-NetworkAdapter -VM $vm -Type Vmxnet3 -NetworkName $NSXVTEPNetwork -StartConnected -confirm:$false | Out-File -Append -LiteralPath $verboseLogFile
New-NetworkAdapter -VM $vm -Type Vmxnet3 -NetworkName $NSXVTEPNetwork -StartConnected -confirm:$false | Out-File -Append -LiteralPath $verboseLogFile
$vm | New-AdvancedSetting -name "ethernet2.filter4.name" -value "dvfilter-maclearn" -confirm:$false -ErrorAction SilentlyContinue | Out-File -Append -LiteralPath $verboseLogFile
$vm | New-AdvancedSetting -Name "ethernet2.filter4.onFailure" -value "failOpen" -confirm:$false -ErrorAction SilentlyContinue | Out-File -Append -LiteralPath $verboseLogFile
$vm | New-AdvancedSetting -name "ethernet3.filter4.name" -value "dvfilter-maclearn" -confirm:$false -ErrorAction SilentlyContinue | Out-File -Append -LiteralPath $verboseLogFile
$vm | New-AdvancedSetting -Name "ethernet3.filter4.onFailure" -value "failOpen" -confirm:$false -ErrorAction SilentlyContinue | 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 Cache VMDK size to $NestedESXiCachingvDisk GB & Capacity VMDK size to $NestedESXiCapacityvDisk GB ..."
Get-HardDisk -Server $viConnection -VM $vm -Name "Hard disk 2" | Set-HardDisk -CapacityGB $NestedESXiCachingvDisk -Confirm:$false | Out-File -Append -LiteralPath $verboseLogFile
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($deployNSXManager -eq 1) {
# Deploy NSX Manager
$nsxMgrOvfConfig = Get-OvfConfiguration $NSXTManagerOVA
$nsxMgrOvfConfig.DeploymentOption.Value = $NSXTMgrDeploymentSize
$nsxMgrOvfConfig.NetworkMapping.Network_1.value = $VMNetwork
$nsxMgrOvfConfig.Common.nsx_role.Value = "NSX Manager"
$nsxMgrOvfConfig.Common.nsx_hostname.Value = $NSXTMgrHostname
$nsxMgrOvfConfig.Common.nsx_ip_0.Value = $NSXTMgrIPAddress
$nsxMgrOvfConfig.Common.nsx_netmask_0.Value = $VMNetmask
$nsxMgrOvfConfig.Common.nsx_gateway_0.Value = $VMGateway
$nsxMgrOvfConfig.Common.nsx_dns1_0.Value = $VMDNS
$nsxMgrOvfConfig.Common.nsx_domain_0.Value = $VMDomain
$nsxMgrOvfConfig.Common.nsx_ntp_0.Value = $VMNTP
if($NSXSSHEnable -eq "true") {
$NSXSSHEnableVar = $true
} else {
$NSXSSHEnableVar = $false
}
$nsxMgrOvfConfig.Common.nsx_isSSHEnabled.Value = $NSXSSHEnableVar
if($NSXEnableRootLogin -eq "true") {
$NSXRootPasswordVar = $true
} else {
$NSXRootPasswordVar = $false
}
$nsxMgrOvfConfig.Common.nsx_allowSSHRootLogin.Value = $NSXRootPasswordVar
$nsxMgrOvfConfig.Common.nsx_passwd_0.Value = $NSXRootPassword
$nsxMgrOvfConfig.Common.nsx_cli_username.Value = $NSXAdminUsername
$nsxMgrOvfConfig.Common.nsx_cli_passwd_0.Value = $NSXAdminPassword
$nsxMgrOvfConfig.Common.nsx_cli_audit_username.Value = $NSXAuditUsername
$nsxMgrOvfConfig.Common.nsx_cli_audit_passwd_0.Value = $NSXAuditPassword
My-Logger "Deploying NSX Manager VM $NSXTMgrDisplayName ..."
$nsxmgr_vm = Import-VApp -Source $NSXTManagerOVA -OvfConfiguration $nsxMgrOvfConfig -Name $NSXTMgrDisplayName -Location $cluster -VMHost $vmhost -Datastore $datastore -DiskStorageFormat thin
My-Logger "Updating vCPU Count to $NSXTMgrvCPU & vMEM to $NSXTMgrvMEM GB ..."
Set-VM -Server $viConnection -VM $nsxmgr_vm -NumCpu $NSXTMgrvCPU -MemoryGB $NSXTMgrvMEM -Confirm:$false | Out-File -Append -LiteralPath $verboseLogFile
My-Logger "Disabling vCPU Reservation ..."
Get-VM -Server $viConnection -Name $nsxmgr_vm | Get-VMResourceConfiguration | Set-VMResourceConfiguration -CpuReservationMhz 0 | Out-File -Append -LiteralPath $verboseLogFile
My-Logger "Powering On $NSXTMgrDisplayName ..."
$nsxmgr_vm | Start-Vm -RunAsync | Out-Null
}
if($deployVCSA -eq 1) {
if($IsWindows) {
$config = (Get-Content -Raw "$($VCSAInstallerPath)\vcsa-cli-installer\templates\install\embedded_vCSA_on_VC.json") | convertfrom-json
} 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'.os.ntp_servers = $VMNTP
$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
#$featureFlags = [pscustomobject] @{
# "prop:guestinfo.cis.feature.states" = "NSX_Integrated=disabled";
# "X:enableHiddenProperties" = "";
#}
#$config.new_vcsa | Add-Member -MemberType NoteProperty -Name "ovftool_arguments" -Value $featureFlags
if($IsWindows) {
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
} elseif($IsMacOS) {
My-Logger "Creating VCSA JSON Configuration file for deployment ..."
$config | ConvertTo-Json | Set-Content -Path "$($ENV:TMPDIR)jsontemplate.json"
My-Logger "Deploying the VCSA ..."
Invoke-Expression "$($VCSAInstallerPath)/vcsa-cli-installer/mac/vcsa-deploy install --no-esx-ssl-verify --accept-eula --acknowledge-ceip $($ENV:TMPDIR)jsontemplate.json"| Out-File -Append -LiteralPath $verboseLogFile
} elseif ($IsLinux) {
My-Logger "Creating VCSA JSON Configuration file for deployment ..."
$config | ConvertTo-Json | Set-Content -Path "/tmp/jsontemplate.json"
My-Logger "Deploying the VCSA ..."
Invoke-Expression "$($VCSAInstallerPath)/vcsa-cli-installer/lin64/vcsa-deploy install --no-esx-ssl-verify --accept-eula --acknowledge-ceip /tmp/jsontemplate.json"| Out-File -Append -LiteralPath $verboseLogFile
}
}
if($deployNSXEdge -eq 1) {
<#
My-Logger "Setting up NSX-T Edge to join NSX-T Management Plane ..."
if(!(Connect-NsxtServer -Server $NSXTMgrHostname -Username $NSXAdminUsername -Password $NSXAdminPassword -WarningAction SilentlyContinue)) {
Write-Host -ForegroundColor Red "Unable to connect to NSX Manager, please check the deployment"
exit
} else {
My-Logger "Successfully logged into NSX-T Manager $NSXTMgrHostname ..."
}
# Retrieve NSX Manager Thumbprint which will be needed later
My-Logger "Retrieving NSX Manager Thumbprint ..."
$nsxMgrID = ((Get-NsxtService -Name "com.vmware.nsx.cluster.nodes").list().results | where {$_.manager_role -ne $null}).id
$nsxMgrCertThumbprint = (Get-NsxtService -Name "com.vmware.nsx.cluster.nodes").get($nsxMgrID).manager_role.api_listen_addr.certificate_sha256_thumbprint
$tokenRegService = Get-NsxtService "com.vmware.nsx.aaa.registration_token"
$token = ($tokenRegService.create()).token
My-Logger "Disconnecting from NSX-T Manager ..."
Disconnect-NsxtServer -Confirm:$false
#>
# Deploy Edges
$nsxEdgeOvfConfig = Get-OvfConfiguration $NSXTEdgeOVA
$NSXTEdgeHostnameToIPs.GetEnumerator() | Sort-Object -Property Value | Foreach-Object {
$VMName = $_.Key
$VMIPAddress = $_.Value
$VMHostname = "$VMName" + "@" + $VMDomain
$nsxEdgeOvfConfig.DeploymentOption.Value = $NSXTEdgeDeploymentSize
$nsxEdgeOvfConfig.NetworkMapping.Network_0.value = $VMNetwork
$nsxEdgeOvfConfig.NetworkMapping.Network_1.value = $NSXVTEPNetwork
$nsxEdgeOvfConfig.NetworkMapping.Network_2.value = $VMNetwork
$nsxEdgeOvfConfig.NetworkMapping.Network_3.value = $VMNetwork
$nsxEdgeOvfConfig.Common.nsx_hostname.Value = $VMHostname
$nsxEdgeOvfConfig.Common.nsx_ip_0.Value = $VMIPAddress
$nsxEdgeOvfConfig.Common.nsx_netmask_0.Value = $VMNetmask
$nsxEdgeOvfConfig.Common.nsx_gateway_0.Value = $VMGateway
$nsxEdgeOvfConfig.Common.nsx_dns1_0.Value = $VMDNS
$nsxEdgeOvfConfig.Common.nsx_domain_0.Value = $VMDomain
$nsxEdgeOvfConfig.Common.nsx_ntp_0.Value = $VMNTP
#$nsxEdgeOvfConfig.Common.mpNodeId.Value = $nsxMgrID
#$nsxEdgeOvfConfig.Common.mpIp.Value = $NSXTMgrIPAddress
#$nsxEdgeOvfConfig.Common.mpThumbprint.Value = $nsxMgrCertThumbprint
if($NSXSSHEnable -eq "true") {
$NSXSSHEnableVar = $true
} else {
$NSXSSHEnableVar = $false
}
$nsxEdgeOvfConfig.Common.nsx_isSSHEnabled.Value = $NSXSSHEnableVar
if($NSXEnableRootLogin -eq "true") {
$NSXRootPasswordVar = $true
} else {
$NSXRootPasswordVar = $false
}
$nsxEdgeOvfConfig.Common.nsx_allowSSHRootLogin.Value = $NSXRootPasswordVar
$nsxEdgeOvfConfig.Common.nsx_passwd_0.Value = $NSXRootPassword
$nsxEdgeOvfConfig.Common.nsx_cli_username.Value = $NSXAdminUsername
$nsxEdgeOvfConfig.Common.nsx_cli_passwd_0.Value = $NSXAdminPassword
$nsxEdgeOvfConfig.Common.nsx_cli_audit_username.Value = $NSXAuditUsername
$nsxEdgeOvfConfig.Common.nsx_cli_audit_passwd_0.Value = $NSXAuditPassword
My-Logger "Deploying NSX Edge VM $VMName ..."
$nsxedge_vm = Import-VApp -Source $NSXTEdgeOVA -OvfConfiguration $nsxEdgeOvfConfig -Name $VMName -Location $cluster -VMHost $vmhost -Datastore $datastore -DiskStorageFormat thin
My-Logger "Updating vCPU Count to $NSXTEdgevCPU & vMEM to $NSXTEdgevMEM GB ..."
Set-VM -Server $viConnection -VM $nsxedge_vm -NumCpu $NSXTEdgevCPU -MemoryGB $NSXTEdgevMEM -Confirm:$false | Out-File -Append -LiteralPath $verboseLogFile
My-Logger "Powering On $VMName ..."
$nsxedge_vm | Start-Vm -RunAsync | Out-Null
}
}
if($moveVMsIntovApp -eq 1) {
My-Logger "Creating vApp $VAppName ..."
$VApp = New-VApp -Name $VAppName -Server $viConnection -Location $cluster
if(-Not (Get-Folder $VMFolder -ErrorAction Ignore)) {
My-Logger "Creating VM Folder $VMFolder ..."
$folder = New-Folder -Name $VMFolder -Server $viConnection -Location (Get-Datacenter $VMDatacenter | Get-Folder vm)
}
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($deployNSXManager -eq 1) {
$nsxMgrVM = Get-VM -Name $NSXTMgrDisplayName -Server $viConnection
My-Logger "Moving $NSXTMgrDisplayName into $VAppName vApp ..."
Move-VM -VM $nsxMgrVM -Server $viConnection -Destination $VApp -Confirm:$false | Out-File -Append -LiteralPath $verboseLogFile
}
if($deployNSXEdge -eq 1) {
My-Logger "Moving NSX Edge VMs into $VAppName vApp ..."
$NSXTEdgeHostnameToIPs.GetEnumerator() | Sort-Object -Property Value | Foreach-Object {
$nsxEdgeVM = Get-VM -Name $_.Key -Server $viConnection
Move-VM -VM $nsxEdgeVM -Server $viConnection -Destination $VApp -Confirm:$false | Out-File -Append -LiteralPath $verboseLogFile
}
}
My-Logger "Moving $VAppName to VM Folder $VMFolder ..."
Move-VApp -Server $viConnection $VAppName -Destination (Get-Folder -Server $viConnection $VMFolder) | Out-File -Append -LiteralPath $verboseLogFile
}
if( $deployNestedESXiVMs -eq 1 -or $deployVCSA -eq 1 -or $deployNSXManager -eq 1 -or $deployNSXEdge -eq 1) {
My-Logger "Disconnecting from $VIServer ..."
Disconnect-VIServer -Server $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
$d = Get-Datacenter -Server $vc $NewVCDatacenterName -ErrorAction Ignore
if( -Not $d) {
My-Logger "Creating Datacenter $NewVCDatacenterName ..."
New-Datacenter -Server $vc -Name $NewVCDatacenterName -Location (Get-Folder -Type Datacenter -Server $vc) | Out-File -Append -LiteralPath $verboseLogFile
}
$c = Get-Cluster -Server $vc $NewVCVSANClusterName -ErrorAction Ignore
if( -Not $c) {
My-Logger "Creating VSAN Cluster $NewVCVSANClusterName ..."
New-Cluster -Server $vc -Name $NewVCVSANClusterName -Location (Get-Datacenter -Name $NewVCDatacenterName -Server $vc) -DrsEnabled -HAEnabled -VsanEnabled | Out-File -Append -LiteralPath $verboseLogFile
(Get-Cluster $NewVCVSANClusterName) | New-AdvancedSetting -Name "das.ignoreRedundantNetWarning" -Type ClusterHA -Value $true -Confirm:$false | 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($configureVSANDiskGroup -eq 1) {
My-Logger "Enabling VSAN & disabling VSAN Health Check ..."
Get-VsanClusterConfiguration -Server $vc -Cluster $NewVCVSANClusterName | Set-VsanClusterConfiguration -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($configureVDS -eq 1) {
$vds = New-VDSwitch -Server $vc -Name $NewVCVDSName -Location (Get-Datacenter -Name $NewVCDatacenterName) -Mtu 1600
New-VDPortgroup -Server $vc -Name $NewVCDVPGName -Vds $vds | Out-File -Append -LiteralPath $verboseLogFile
foreach ($vmhost in Get-Cluster -Server $vc | Get-VMHost) {
My-Logger "Adding $vmhost to $NewVCVDSName"
$vds | Add-VDSwitchVMHost -VMHost $vmhost | Out-Null
$vmhostNetworkAdapter = Get-VMHost $vmhost | Get-VMHostNetworkAdapter -Physical -Name vmnic1