-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathVMware.CloudFoundation.InstanceRecovery.psm1
More file actions
5703 lines (5061 loc) · 320 KB
/
VMware.CloudFoundation.InstanceRecovery.psm1
File metadata and controls
5703 lines (5061 loc) · 320 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
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
# Copyright 2025 Broadcom. All Rights Reserved.
# SPDX-License-Identifier: BSD-2
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
If ($PSEdition -eq 'Core') {
$Script:PSDefaultParameterValues = @{
"invoke-restmethod:SkipCertificateCheck" = $true
"invoke-webrequest:SkipCertificateCheck" = $true
}
} else {
Add-Type @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
public bool CheckValidationResult(
ServicePoint srvPoint, X509Certificate certificate,
WebRequest request, int certificateProblem) {
return true;
}
}
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
}
#Region Supporting Functions
Function Filter-X509() {
begin {
$doOutput = $false
}
process {
if ( $_.Contains("-----BEGIN CERTIFICATE-----") ) {
$doOutput = $true
}
if ($doOutput) {
Write-Output $_
}
if ( $_.Contains("-----END CERTIFICATE-----") ) {
$doOutput = $false
}
}
end {
if ($doOutput) {
throw "still printing certificate"
}
}
}
Function catchWriter {
<#
.SYNOPSIS
Prints a controlled error message after a failure
.DESCRIPTION
Accepts the invocation object from a failure in a Try/Catch block and prints back more precise information regarding
the cause of the failure
.EXAMPLE
catchWriter -object $_
This example when placed in a catch block will return error message, line number and line text (command) issued
#>
Param(
[Parameter(mandatory = $true)]
[PSObject]$object
)
$lineNumber = $object.InvocationInfo.ScriptLineNumber
$lineText = $object.InvocationInfo.Line.trim()
$errorMessage = $object.Exception.Message
Write-Error "Error at Script Line $lineNumber"
Write-Error "Relevant Command: $lineText"
Write-Error "Error Message: $errorMessage"
}
Function Get-InstalledSoftware {
$software = @()
$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $env:COMPUTERNAME)
$apps = $reg.OpenSubKey("SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall").GetSubKeyNames()
foreach ($app in $apps) {
$program = $reg.OpenSubKey("SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\$app")
$name = $program.GetValue('DisplayName')
$software += $name
}
$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $env:COMPUTERNAME)
$apps = $reg.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall").GetSubKeyNames()
foreach ($app in $apps) {
$program = $reg.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$app")
$name = $program.GetValue('DisplayName')
$software += $name
}
$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('CurrentUser', $env:COMPUTERNAME)
$apps = $reg.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall").GetSubKeyNames()
foreach ($app in $apps) {
$program = $reg.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$app")
$name = $program.GetValue('DisplayName')
$software += $name
}
Return $software
}
Function LogMessage {
Param (
[Parameter (Mandatory = $true)] [AllowEmptyString()] [String]$message,
[Parameter (Mandatory = $false)] [Switch]$nonewline,
[Parameter (Mandatory = $false)] [ValidateSet("INFO", "ERROR", "WARNING", "EXCEPTION", "ADVISORY", "NOTE", "QUESTION", "WAIT")] [String]$type = "INFO"
)
If (!$colour) {
$colour = "92m" #Green
}
If ($type -eq "INFO") {
$messageColour = "92m" #Green
} elseIf ($type -in "ERROR", "EXCEPTION") {
$messageColour = "91m" # Red
} elseIf ($type -in "WARNING", "ADVISORY", "QUESTION") {
$messageColour = "93m" #Yellow
} elseIf ($type -in "NOTE", "WAIT") {
$messageColour = "97m" # White
}
<#
Reference Colours
31m Red
32m Green
33m Yellow
36m Cyan
37m White
91m Bright Red
92m Bright Green
93m Bright Yellow
95m Bright Magenta
96m Bright Cyan
97m Bright White
#>
$ESC = [char]0x1b
$timeStamp = Get-Date -Format "MM-dd-yyyy_HH:mm:ss"
$timestampColour = "97m"
If ($nonewline) {
Write-Host "$ESC[${timestampcolour} [$timestamp]$ESC[${messageColour} [$type] $message$ESC[0m" -NoNewline
} else {
Write-Host "$ESC[${timestampcolour} [$timestamp]$ESC[${messageColour} [$type] $message$ESC[0m"
}
#$logContent = '[' + $timeStamp + '] [' +$threadTag + '] ' + $type + ' ' + $message
#Add-Content -path $logFile $logContent
}
Function Test-MemberOfSubnet {
[cmdletbinding()]
[outputtype([System.Boolean])]
param(
[parameter(Mandatory = $true)]
[string] $IPAddress,
[parameter(Mandatory = $true)]
[string] $Subnet
)
# Split Subnet into the address and the CIDR notation
[String]$CIDRAddress = $Subnet.Split('/')[0]
[int]$CIDRBits = $Subnet.Split('/')[1]
# Address from Subnet and the search address are converted to Int32 and the full mask is calculated from the CIDR notation.
[int]$BaseAddress = [System.BitConverter]::ToInt32((([System.Net.IPAddress]::Parse($CIDRAddress)).GetAddressBytes()), 0)
[int]$Address = [System.BitConverter]::ToInt32(([System.Net.IPAddress]::Parse($IPAddress).GetAddressBytes()), 0)
[int]$Mask = [System.Net.IPAddress]::HostToNetworkOrder(-1 -shl ( 32 - $CIDRBits))
# Determine whether the address is in the Subnet.
If (($BaseAddress -band $Mask) -eq ($Address -band $Mask)) { $true } else { $false }
}
Function VCFIRCreateHeader {
Param(
[Parameter (Mandatory = $true)]
[String] $username,
[Parameter (Mandatory = $true)]
[String] $password
)
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username, $password))) # Create Basic Authentication Encoded Credentials
$headers = @{"Accept" = "application/json" }
$headers.Add("Authorization", "Basic $base64AuthInfo")
Return $headers
}
Function Move-VMKernel {
Param (
[object]$VMHost,
[string]$Interface,
[string]$NetworkName
)
#Get Network ID
$networkid = $VMHost.ExtensionData.Configmanager.NetworkSystem
# ------- UpdateVirtualNic ------- Migrate adapter to Vswitch
$nic = New-Object VMware.Vim.HostVirtualNicSpec
$nic.portgroup = $NetworkName
$_this = Get-View -Id $networkid
$_this.UpdateVirtualNic($Interface, $nic)
}
Function cidrToMask {
Param (
[Parameter (Mandatory = $true)] [String]$cidr
)
$subnetMasks = @(
($32 = @{ cidr = "32"; mask = "255.255.255.255" }),
($31 = @{ cidr = "31"; mask = "255.255.255.254" }),
($30 = @{ cidr = "30"; mask = "255.255.255.252" }),
($29 = @{ cidr = "29"; mask = "255.255.255.248" }),
($28 = @{ cidr = "28"; mask = "255.255.255.240" }),
($27 = @{ cidr = "27"; mask = "255.255.255.224" }),
($26 = @{ cidr = "26"; mask = "255.255.255.192" }),
($25 = @{ cidr = "25"; mask = "255.255.255.128" }),
($24 = @{ cidr = "24"; mask = "255.255.255.0" }),
($23 = @{ cidr = "23"; mask = "255.255.254.0" }),
($22 = @{ cidr = "22"; mask = "255.255.252.0" }),
($21 = @{ cidr = "21"; mask = "255.255.248.0" }),
($20 = @{ cidr = "20"; mask = "255.255.240.0" }),
($19 = @{ cidr = "19"; mask = "255.255.224.0" }),
($18 = @{ cidr = "18"; mask = "255.255.192.0" }),
($17 = @{ cidr = "17"; mask = "255.255.128.0" }),
($16 = @{ cidr = "16"; mask = "255.255.0.0" }),
($15 = @{ cidr = "15"; mask = "255.254.0.0" }),
($14 = @{ cidr = "14"; mask = "255.252.0.0" }),
($13 = @{ cidr = "13"; mask = "255.248.0.0" }),
($12 = @{ cidr = "12"; mask = "255.240.0.0" }),
($11 = @{ cidr = "11"; mask = "255.224.0.0" }),
($10 = @{ cidr = "10"; mask = "255.192.0.0" }),
($9 = @{ cidr = "9"; mask = "255.128.0.0" }),
($8 = @{ cidr = "8"; mask = "255.0.0.0" }),
($7 = @{ cidr = "7"; mask = "254.0.0.0" }),
($6 = @{ cidr = "6"; mask = "252.0.0.0" }),
($5 = @{ cidr = "5"; mask = "248.0.0.0" }),
($4 = @{ cidr = "4"; mask = "240.0.0.0" }),
($3 = @{ cidr = "3"; mask = "224.0.0.0" }),
($2 = @{ cidr = "2"; mask = "192.0.0.0" }),
($1 = @{ cidr = "1"; mask = "128.0.0.0" }),
($0 = @{ cidr = "0"; mask = "0.0.0.0" })
)
$foundMask = $subnetMasks | Where-Object { $_.'cidr' -eq $cidr }
Return $foundMask.mask
}
#EndRegion Supporting Functions
#Region Pre-Requisites
Function Confirm-VCFInstanceRecoveryPreReqs {
<#
.SYNOPSIS
Checks for the presence of supporting software and modules leveraged by VMware.CloudFoundation.InstanceRecovery
.DESCRIPTION
The Confirm-VCFInstanceRecoveryPreReqs cmdlet checks for the presence of supporting software and modules leveraged by VMware.CloudFoundation.InstanceRecovery
.EXAMPLE
Confirm-VCFInstanceRecoveryPreReqs
#>
#Check Dependencies
$jumpboxName = hostname
#Check for windows tar.exe
$isTarInstalled = Test-Path "C:\Windows\System32\tar.exe"
If (!$isTarInstalled) {
LogMessage -type WARNING -message "[$jumpboxName] tar.exe Missing. Please install"
} else {
LogMessage -type INFO -message "[$jumpboxName] tar.exe found"
}
$isPoshSSHInstalled = Get-InstalledModule -name "Posh-SSH" -RequiredVersion "3.0.8" -ErrorAction SilentlyContinue
If (!$isPoshSSHInstalled) {
LogMessage -type WARNING -message "[$jumpboxName] Posh-SSH Module Missing. Please install"
} else {
LogMessage -type INFO -message "[$jumpboxName] Posh-SSH Module found"
}
$isPowerCLIInstalled = Get-InstalledModule -name "VCF.PowerCLI" -ErrorAction SilentlyContinue
If (!$isPowerCLIInstalled) {
LogMessage -type WARNING -message "[$jumpboxName] VCF PowerCLI Module Missing. Please install"
} else {
LogMessage -type INFO -message "[$jumpboxName] PowerCLI Module found"
}
$installedSoftware = Get-InstalledSoftware
If (!($installedSoftware -match "OpenSSL")) {
$openSslUrlPath = "https://slproweb.com/products/Win32OpenSSL.html"
Try { $openSslLinks = Invoke-WebRequest $openSslUrlPath -UseBasicParsing -ErrorAction silentlycontinue }Catch {}
$openSslLink = (($openSslLinks.Links | Where-Object { $_.href -like "/download/Win64OpenSSL_Light*.exe" }).href)[0]
$Global:openSSLUrl = "https://slproweb.com" + $openSslLink
If ($openSSLUrl) {
LogMessage -type WARNING -message "[$jumpboxName] OpenSSL missing. Please install. Latest version detected is here: $openSSLUrl"
} else {
LogMessage -type WARNING -message "[$jumpboxName] OpenSSL missing. Please install. Unable to detect latest version on web"
}
} else {
LogMessage -type INFO -message "[$jumpboxName] OpenSSL Utility found"
}
$pathEntries = $env:path -split (";")
$OpenSSLPath = $pathEntries | Where-Object { $_ -like "*OpenSSL*" }
If ($OpenSSLPath) {
$testOpenSSExe = Test-Path "$OpenSSLPath\openssl.exe"
IF ($testOpenSSExe) {
LogMessage -type INFO -message "[$jumpboxName] openssl.exe found in $OpenSSLPath"
} else {
LogMessage -type WARNING -message "[$jumpboxName] $OpenSSLPath was found in environment path, but no openssl.exe was found in that path"
}
} else {
LogMessage -type WARNING -message "[$jumpboxName] No folder path that looks like OpenSSL was discovered in the environment path variable. Please double check that the location of OpenSSL is included in the path variable"
}
$viServerModeConfig = (Get-PowerCLIConfiguration | Where-Object { $_.scope -eq "AllUsers" }).DefaultVIServerMode
If ($viServerModeConfig -eq 'Multiple') {
LogMessage -type INFO -message "[$jumpboxName] DefaultVIServerMode is correctly set to 'Multiple'"
} else {
LogMessage -type WARNING -message "[$jumpboxName] DefaultVIServerMode is not correctly set. Please run 'Set-PowerCLIConfiguration -DefaultVIServerMode Multiple' to correct"
}
}
Export-ModuleMember -Function Confirm-VCFInstanceRecoveryPreReqs
#EndRegion Pre-Requisites
#Region Data Gathering
Function New-ExtractDataFromSDDCBackup {
<#
.SYNOPSIS
Decrypts and extracts the contents of the provided VMware Cloud Foundation SDDC manager backup, parses it for information required for instance recovery and stores the data in a file called extracted-sddc-data.json
.DESCRIPTION
The New-ExtractDataFromSDDCBackup cmdlet decrypts and extracts the contents of the provided VMware Cloud Foundation SDDC manager backup, parses it for information required for instance recovery and stores the data in a file called extracted-sddc-data.json
.EXAMPLE
New-ExtractDataFromSDDCBackup -backupFilePath "F:\backup\vcf-backup-sfo-vcf01-sfo-rainpole-io-2023-09-19-10-53-02.tar.gz" -encryptionPassword "VMw@re1!VMw@re1!"
.PARAMETER vcfBackupFilePath
Relative or absolute to the VMware Cloud Foundation SDDC manager backup file somewhere on the local filesystem
.PARAMETER encryptionPassword
The password that should be used to decrypt the VMware Cloud Foundation SDDC manager backup file ie the password that was used to encrypt it originally.
#>
Param(
[Parameter (Mandatory = $true)][String] $vcfBackupFilePath,
[Parameter (Mandatory = $true)][String] $encryptionPassword
)
$jumpboxName = hostname
LogMessage -type NOTE -message "[$jumpboxName] Starting Task $($MyInvocation.MyCommand)"
$backupFileFullPath = (Resolve-Path -Path $vcfBackupFilePath).path
$backupFileName = (Get-ChildItem -path $backupFileFullPath).name
$parentFolder = Split-Path -Path $backupFileFullPath
$extractedBackupFolder = ($backupFileName -Split (".tar.gz"))[0]
#Decrypt Backup
LogMessage -type INFO -message "[$jumpboxName] Decrypting Backup"
$command = "openssl enc -d -aes-256-cbc -md sha256 -in $backupFileFullPath -pass pass:`"$encryptionPassword`" -out `"$parentFolder\decrypted-sddc-manager-backup.tar.gz`""
Invoke-Expression "& $command" *>$null
#Extract Required Files From Backup Leveraging Windows tar.exe
LogMessage -type INFO -message "[$jumpboxName] Extracting Backup"
Set-Location "$parentFolder"
tar -xzf "$parentFolder\decrypted-sddc-manager-backup.tar.gz" "$extractedBackupFolder/metadata.json" "$extractedBackupFolder/appliancemanager_dns_configuration.json" "$extractedBackupFolder/appliancemanager_ntp_configuration.json" "$extractedBackupFolder/security_password_vault.json" "$extractedBackupFolder/database/sddc-postgres.bkp"
#Get Content of Password Vault
LogMessage -type INFO -message "[$jumpboxName] Reading Password Vault"
$passwordVaultJson = Get-Content "$parentFolder\$extractedBackupFolder\security_password_vault.json" | ConvertFrom-JSON
$passwordVaultObject = @()
Foreach ($object in $passwordVaultJson) {
$passwordVaultObject += [pscustomobject]@{
'entityId' = $object.entityId
'entityName' = $object.entityName
'entityType' = $object.entityType
'credentialType' = $object.credentialType
'entityIpAddress' = $object.entityIpAddress
'username' = $object.username
'domainName' = $object.domainName
'password' = $object.password
}
}
#Get Management Domain Deployment Objects
$metadataJSON = Get-Content "$parentFolder\$extractedBackupFolder\metadata.json" | ConvertFrom-JSON
$dnsJSON = Get-Content "$parentFolder\$extractedBackupFolder\appliancemanager_dns_configuration.json" | ConvertFrom-JSON
$ntpJSON = Get-Content "$parentFolder\$extractedBackupFolder\appliancemanager_ntp_configuration.json" | ConvertFrom-JSON
#$mgmtVcenterMetadata = Get-Content -Path ($vCenterbackupFolderFullPath + "/backup-metadata.json") | ConvertFrom-JSON
#$managementSubnetMask = cidrToMask $mgmtVcenterMetadata.PrimaryNetworkInfo.ipv4.prefix
$sddcManagerIP = $metadataJSON.ip
#$managementSubnetMask = $metaDataJSON.netmask
$ip = [ipaddress]$sddcManagerIP
$subnet = [ipaddress]$metaDataJSON.netmask
$netid = [ipaddress]($ip.address -band $subnet.address)
$managementSubnet = $($netid.ipaddresstostring)
$mgmtDomainInfrastructure = [pscustomobject]@{
'port_group' = $metadataJSON.port_group
'vsan_datastore' = $metadataJSON.vsan_datastore
'cluster' = $metaDataJSON.cluster
'datacenter' = $metaDataJSON.datacenter
'netmask' = $metaDataJSON.netmask
'subnet' = $managementSubnet
'gateway' = $metaDataJSON.gateway
'domain' = $metaDataJSON.domain
'search_path' = $metaDataJSON.search_path
'primaryDnsServer' = $dnsJSON.primaryDnsServer
'secondaryDnsServer' = $dnsJSON.secondaryDnsServer
'ntpServers' = @($ntpJSON.ntpServers)
}
$psqlContent = Get-Content "$parentFolder\$extractedBackupFolder\database\sddc-postgres.bkp"
LogMessage -type INFO -message "[$jumpboxName] Retrieving SDDC Manager Detail"
#GetDomainDetails
$ceipStartingLineNumber = ($psqlContent | Select-String -SimpleMatch "COPY public.sddc_manager_controller" | Select-Object Line, LineNumber).LineNumber
$lineContent = $psqlContent | Select-Object -Index $ceipStartingLineNumber
$sddcManagerIp = $lineContent.split("`t")[3]
$sddcManagerVersion = $lineContent.split("`t")[5]
$sddcManagerFqdn = $lineContent.split("`t")[6]
$sddcManagerVmName = $lineContent.split("`t")[8]
If ($lineContent.split("`t")[9] -eq 'ENABLED') { $ceipStatus = $true } else { $ceipStatus = $false }
$sddcManagerObject = @()
$sddcManagerObject += [pscustomobject]@{
'fqdn' = $sddcManagerFqdn
'vmname' = $sddcManagerVmName
'ip' = (Resolve-DnsName $sddcManagerFqdn).IPAddress
'fips_enabled' = $metadataJSON.fips_enabled
'ceip_enabled' = $ceipStatus
'version' = $sddcManagerVersion
}
LogMessage -type INFO -message "[$jumpboxName] Retrieving NSX Manager Details"
#Get All NSX Manager Clusters
$nsxManagerstartingLineNumber = ($psqlContent | Select-String -SimpleMatch "COPY public.nsxt (id" | Select-Object Line, LineNumber).LineNumber
$nsxManagerlineIndex = $nsxManagerstartingLineNumber
$nsxtManagerClusters = @()
Do {
$lineContent = $psqlContent | Select-Object -Index $nsxManagerlineIndex
If ($lineContent -ne '\.') {
$nodeContent = (($lineContent.split("`t")[9]).replace("\n", "")) | ConvertFrom-Json
$nodeIPs = ($nodeContent.managerIpsFqdnMap | Get-Member -type NoteProperty).name
$nsxNodes = @()
Foreach ($nodeIP in $nodeIPs) {
$hostname = $nodeContent.managerIpsFqdnMap.$($nodeIP)
$nsxNodes += [pscustomobject]@{
'vmName' = $hostname.split(".")[0]
'hostname' = $hostname
'ip' = $nodeIP
}
}
$nsxtManagerClusters += [pscustomobject]@{
'clusterVip' = $lineContent.split("`t")[5]
'clusterFqdn' = $lineContent.split("`t")[6]
'domainIDs' = $nodeContent.domainIds
'nsxNodes' = $nsxNodes
}
}
$nsxManagerlineIndex++
}
Until ($lineContent -eq '\.')
#Get Hosts
LogMessage -type INFO -message "[$jumpboxName] Retrieving Host Details"
$hostsLineNumber = ($psqlContent | Select-String -SimpleMatch "COPY public.host " | Select-Object Line, LineNumber).LineNumber
$hostsLineIndex = $hostsLineNumber
$hosts = @()
Do {
$lineContent = $psqlContent | Select-Object -Index $hostsLineIndex
If ($lineContent -ne '\.') {
$hostId = $lineContent.split("`t")[0]
$gateway = $lineContent.split("`t")[7]
$hostName = $lineContent.split("`t")[9]
$hostMgmtIp = (Resolve-DnsName $lineContent.split("`t")[9]).IPAddress
$hostMask = $lineContent.split("`t")[17]
$hostVersion = $lineContent.split("`t")[18]
$hostVmotionIp = $lineContent.split("`t")[19]
$hostVsanIP = $lineContent.split("`t")[20]
#Calculate Managment Subnet (Management Domain Hosts Only)
If (($gateway -ne "\N") -AND ($hostMask -ne "\N")) {
$ip = [ipaddress]$hostMgmtIp
$subnet = [ipaddress]$hostMask
$netid = [ipaddress]($ip.address -band $subnet.address)
$hostManagementSubnet = $($netid.ipaddresstostring)
}
$hosts += [pscustomobject]@{
'id' = $hostId
'gateway' = $gateway
'hostName' = $hostName
'mgmtIp' = $hostMgmtIp
'mask' = $hostMask
'subnet' = $hostManagementSubnet
'version' = $hostVersion
'vmotionIP' = $hostVmotionIp
'vsanIP' = $hostVsanIP
}
}
$hostsLineIndex++
}
Until ($lineContent -eq '\.')
#Get Host and Domain Details
LogMessage -type INFO -message "[$jumpboxName] Retrieving Host and Domain Mappings"
$hostsAndDomainsLineNumber = ($psqlContent | Select-String -SimpleMatch "COPY public.host_and_domain " | Select-Object Line, LineNumber).LineNumber
$hostsAndDomainsLineIndex = $hostsAndDomainsLineNumber
$hostsAndDomains = @()
Do {
$lineContent = $psqlContent | Select-Object -Index $hostsAndDomainsLineIndex
If ($lineContent -ne '\.') {
$hostId = $lineContent.split("`t")[0]
$domainID = $lineContent.split("`t")[1]
$hostsAndDomains += [pscustomobject]@{
'hostId' = $hostId
'domainID' = $domainID
}
}
$hostsAndDomainsLineIndex++
}
Until ($lineContent -eq '\.')
#Get Host and vCenter Details
LogMessage -type INFO -message "[$jumpboxName] Retrieving Host and vCenter Mappings"
$hostsandVcentersLineNumber = ($psqlContent | Select-String -SimpleMatch "COPY public.host_and_vcenter " | Select-Object Line, LineNumber).LineNumber
$hostsandVcentersLineIndex = $hostsandVcentersLineNumber
$hostsandVcenters = @()
Do {
$lineContent = $psqlContent | Select-Object -Index $hostsandVcentersLineIndex
If ($lineContent -ne '\.') {
$hostId = $lineContent.split("`t")[0]
$vCenterID = $lineContent.split("`t")[1]
$hostsandVcenters += [pscustomobject]@{
'hostId' = $hostId
'vCenterID' = $vCenterID
}
}
$hostsandVcentersLineIndex++
}
Until ($lineContent -eq '\.')
#Get Host and vCenter Details
LogMessage -type INFO -message "[$jumpboxName] Retrieving vCenter Details"
$vCentersStartingLineNumber = ($psqlContent | Select-String -SimpleMatch "COPY public.vcenter " | Select-Object Line, LineNumber).LineNumber
$vCenterLineIndex = $vCentersStartingLineNumber
$vCenters = @()
Do {
$lineContent = $psqlContent | Select-Object -Index $vCentersStartingLineNumber
If ($lineContent -ne '\.') {
$vCenterID = $lineContent.split("`t")[0]
$vCenterVersion = $lineContent.split("`t")[9]
$vCenterFqdn = $lineContent.split("`t")[10]
$vCenterIp = (Resolve-DnsName $vCenterFqdn).IPAddress
$vCenterVMname = $lineContent.split("`t")[12]
$vCenterDomainID = ($hostsAndDomains | Where-Object { $_.hostId -eq (($hostsandVcenters | Where-Object { $_.vCenterID -eq $vCenterID })[0].hostID) }).domainID
$vCenters += [pscustomobject]@{
'vCenterID' = $vCenterID
'vCenterVersion' = $vCenterVersion
'vCenterFqdn' = $vCenterFqdn
'vCenterIp' = $vCenterIp
'vCenterVMname' = $vCenterVMname
'vCenterDomainID' = $vCenterDomainID
}
}
$vCentersStartingLineNumber++
}
Until ($lineContent -eq '\.')
#Get Hosts and Pools
LogMessage -type INFO -message "[$jumpboxName] Retrieving Host and Network Pool Mappings"
$hostsAndPoolsLineNumber = ($psqlContent | Select-String -SimpleMatch "COPY public.host_and_network_pool" | Select-Object Line, LineNumber).LineNumber
$hostsAndPoolsLineIndex = $hostsAndPoolsLineNumber
$hostsandPools = @()
Do {
$lineContent = $psqlContent | Select-Object -Index $hostsAndPoolsLineIndex
If ($lineContent -ne '\.') {
$hostId = $lineContent.split("`t")[1]
$poolID = $lineContent.split("`t")[2]
$hostsandPools += [pscustomobject]@{
'hostId' = $hostId
'poolId' = $poolID
}
}
$hostsAndPoolsLineIndex++
}
Until ($lineContent -eq '\.')
#Get Network Pools
LogMessage -type INFO -message "[$jumpboxName] Retrieving Network Pool Details"
$networkPoolsLineNumber = ($psqlContent | Select-String -SimpleMatch "COPY public.network_pool " | Select-Object Line, LineNumber).LineNumber
$networkPoolsLineIndex = $networkPoolsLineNumber
$networkPools = @()
Do {
$lineContent = $psqlContent | Select-Object -Index $networkPoolsLineIndex
If ($lineContent -ne '\.') {
$poolID = $lineContent.split("`t")[0]
$poolName = $lineContent.split("`t")[3]
$networkPools += [pscustomobject]@{
'poolID' = $poolID
'poolName' = $poolName
}
}
$networkPoolsLineIndex++
}
Until ($lineContent -eq '\.')
#Get VDSs
LogMessage -type INFO -message "[$jumpboxName] Retrieving vDS Details"
$vdsLineNumber = ($psqlContent | Select-String -SimpleMatch "COPY public.vds" | Select-Object Line, LineNumber).LineNumber
$vdsLineIndex = $vdsLineNumber
$virtualDistributedSwitches = @()
Do {
$lineContent = $psqlContent | Select-Object -Index $vdsLineIndex
If ($lineContent -ne '\.') {
$vdsId = $lineContent.split("`t")[0]
$vdsMtu = $lineContent.split("`t")[3]
$vdsName = $lineContent.split("`t")[4]
$niocs = $lineContent.split("`t")[5] | ConvertFrom-Json
If ($lineContent.split("`t")[6] -ne '\N') {
$vdsPortgroups = $lineContent.split("`t")[6] | ConvertFrom-Json
} else {
$vdsPortgroups = $null
}
$sourceID = $lineContent.split("`t")[10]
$version = $lineContent.split("`t")[8]
$virtualDistributedSwitch = [pscustomobject]@{
'Id' = $vdsId
'niocs' = $niocs
'Mtu' = $vdsMtu
'Name' = $vdsName
'PortGroups' = $vdsPortgroups
'version' = $version
'sourceID' = $sourceID
}
If ($lineContent.split("`t")[11] -ne '\N') {
$overlayContent = $lineContent.split("`t")[11] | ConvertFrom-Json
$transportZoneContent = $overlayContent.transportZones
If ($overlayContent.hostSwitchOperationalMode -ne $null) {
$hostSwitchOperationalModeContent = $overlayContent.hostSwitchOperationalMode
} else {
$hostSwitchOperationalModeContent = 'STANDARD'
}
$virtualDistributedSwitch | Add-Member -NotePropertyName 'transportZones' -NotePropertyValue $transportZoneContent
$virtualDistributedSwitch | Add-Member -NotePropertyName 'hostSwitchOperationalMode' -NotePropertyValue $hostSwitchOperationalModeContent
}
$virtualDistributedSwitches += $virtualDistributedSwitch
}
$vdsLineIndex++
}
Until ($lineContent -eq '\.')
#Get Networks
LogMessage -type INFO -message "[$jumpboxName] Retrieving Network Details"
$networksLineNumber = ($psqlContent | Select-String -SimpleMatch "COPY public.vcf_network " | Select-Object Line, LineNumber).LineNumber
$networksLineIndex = $networksLineNumber
$networks = @()
Do {
$lineContent = $psqlContent | Select-Object -Index $networksLineIndex
If ($lineContent -ne '\.') {
$id = $lineContent.split("`t")[0]
$gateway = $lineContent.split("`t")[4]
$ipInclusionRanges = $lineContent.split("`t")[5] | ConvertFrom-Json
$startIPAddress = $ipInclusionRanges.start
$endIPAddress = $ipInclusionRanges.end
$mtu = $lineContent.split("`t")[6]
$subnet = $lineContent.split("`t")[7]
$subnetMask = $lineContent.split("`t")[8]
$type = $lineContent.split("`t")[9]
$vlanId = $lineContent.split("`t")[11]
$networks += [pscustomobject]@{
'id' = $id
'gateway' = $gateway
'startIPAddress' = $startIPAddress
'endIPAddress' = $endIPAddress
'mtu' = $mtu
'subnet' = $subnet
'subnetMask' = $subnetMask
'type' = $type
'vlanId' = $vlanId
}
}
$networksLineIndex++
}
Until ($lineContent -eq '\.')
#Get Pools and Networks
LogMessage -type INFO -message "[$jumpboxName] Retrieving Network Pools and Network Mappings"
$poolsAndNetworksLineNumber = ($psqlContent | Select-String -SimpleMatch "COPY public.vcf_network_and_network_pool" | Select-Object Line, LineNumber).LineNumber
$poolsAndNetworksLineIndex = $poolsAndNetworksLineNumber
$poolsAndNetworks = @()
Do {
$lineContent = $psqlContent | Select-Object -Index $poolsAndNetworksLineIndex
If ($lineContent -ne '\.') {
$networkID = $lineContent.split("`t")[0]
$poolID = $lineContent.split("`t")[1]
$poolsAndNetworks += [pscustomobject]@{
'networkID' = $networkID
'poolID' = $poolID
}
}
$poolsAndNetworksLineIndex++
}
Until ($lineContent -eq '\.')
#Get Cluster and VDS
LogMessage -type INFO -message "[$jumpboxName] Retrieving Cluster and vDS Mappings"
$clusterAndVdsLineNumber = ($psqlContent | Select-String -SimpleMatch "COPY public.cluster_and_vds" | Select-Object Line, LineNumber).LineNumber
$clusterAndVdsLineIndex = $clusterAndVdsLineNumber
$clusterAndVds = @()
Do {
$lineContent = $psqlContent | Select-Object -Index $clusterAndVdsLineIndex
If ($lineContent -ne '\.') {
$clusterID = $lineContent.split("`t")[1]
$vdsID = $lineContent.split("`t")[2]
$clusterAndVds += [pscustomobject]@{
'clusterID' = $clusterID
'vdsID' = $vdsID
}
}
$clusterAndVdsLineIndex++
}
Until ($lineContent -eq '\.')
LogMessage -type INFO -message "[$jumpboxName] Retrieving Host to Cluster Mappings"
$hostAndClusterLineNumber = ($psqlContent | Select-String -SimpleMatch "COPY public.host_and_cluster " | Select-Object Line, LineNumber).LineNumber
$hostAndClusterLineIndex = $hostAndClusterLineNumber
$hostAndCluster = @()
Do {
$lineContent = $psqlContent | Select-Object -Index $hostAndClusterLineIndex
If ($lineContent -ne '\.') {
$hostID = $lineContent.split("`t")[0]
$clusterID = $lineContent.split("`t")[1]
$hostAndCluster += [pscustomobject]@{
'hostID' = $hostID
'clusterID' = $clusterID
}
}
$hostAndClusterLineIndex++
}
Until ($lineContent -eq '\.')
#Get Clusters
LogMessage -type INFO -message "[$jumpboxName] Retrieving Cluster Details"
$clustersLineNumber = ($psqlContent | Select-String -SimpleMatch "COPY public.cluster " | Select-Object Line, LineNumber).LineNumber
$clustersLineIndex = $clustersLineNumber
$clusters = @()
Do {
$lineContent = $psqlContent | Select-Object -Index $clustersLineIndex
If ($lineContent -ne '\.') {
$id = $lineContent.split("`t")[0]
$datacenter = $lineContent.split("`t")[3]
$ftt = $lineContent.split("`t")[4]
$isDefault = $lineContent.split("`t")[5]
$isStretched = $lineContent.split("`t")[6]
#$name = $lineContent.split("`t")[7]
$vCenterID = $lineContent.split("`t")[9]
$primaryDatastoreName = $lineContent.split("`t")[12]
$primaryDatastoreType = $lineContent.split("`t")[13]
$sourceID = $lineContent.split("`t")[14]
$isImagedBased = $lineContent.split("`t")[18]
$vdsDetails = @()
#Experimental
$clusterHosts = $hostAndCluster | Where-Object { $_.clusterID -eq $id }
$hostsArray = @()
Foreach ($clusterHost in $clusterHosts) {
$hostname = ($hosts | Where-Object { $_.id -eq $clusterHost.hostId }).hostname
$gateway = ($hosts | Where-Object { $_.id -eq $clusterHost.hostId }).gateway
$mask = ($hosts | Where-Object { $_.id -eq $clusterHost.hostId }).mask
$subnet = ($hosts | Where-Object { $_.id -eq $clusterHost.hostId }).subnet
$networkPoolID = ($hostsAndPools | Where-Object { $_.hostId -eq $clusterHost.hostId }).poolId
$hostNetworkIds = ($poolsAndNetworks | Where-Object { $_.poolID -eq $networkPoolID }).networkId
$hostNetworks = @()
$hostNetworks += [pscustomobject]@{
'type' = "MANAGEMENT"
'gateway' = $gateway
'mtu' = "1500"
'mask' = $mask
'subnet' = $subnet
}
$hostNetworks += $networks | Where-Object { $_.id -in $hostNetworkIds }
$hostsArray += [pscustomobject]@{
'hostname' = $hostname
'networkPoolID' = $networkPoolID
'hostNetworkIds' = $hostNetworkIds
'networks' = $hostNetworks
}
}
#End Experimental
Foreach ($vds in ($clusterAndVds | Where-Object { $_.clusterID -eq $id })) {
$virtualDistributedSwitchDetails = $virtualDistributedSwitches | Where-Object { $_.id -eq $vds.vdsId }
$niocSpecsObject = @()
Foreach ($niocSpec in $virtualDistributedSwitchDetails.niocs) {
$niocSpecsObject += [PSCustomObject]@{
'trafficType' = $niocSpec.network
'value' = ($niocSpec.level).toUpper()
}
}
$vdsObject = New-Object -type PSObject
$vdsObject | Add-Member -NotePropertyName 'mtu' -NotePropertyValue $virtualDistributedSwitchDetails.mtu
$vdsObject | Add-Member -NotePropertyName 'niocSpecs' -NotePropertyValue $niocSpecsObject
$vdsObject | Add-Member -NotePropertyName 'portgroups' -NotePropertyValue $virtualDistributedSwitchDetails.portgroups
$vdsObject | Add-Member -NotePropertyName 'dvsName' -NotePropertyValue $virtualDistributedSwitchDetails.name
$vdsObject | Add-Member -NotePropertyName 'id' -NotePropertyValue $vds.vdsId
$vdsObject | Add-Member -NotePropertyName 'sourceID' -NotePropertyValue $virtualDistributedSwitchDetails.sourceID
$vdsObject | Add-Member -NotePropertyName 'vmnics' -NotePropertyValue $null
$vdsObject | Add-Member -NotePropertyName 'networks' -NotePropertyValue ("VM_MANAGEMENT", "MANAGEMENT", "VSAN", "VMOTION" | Where-Object { $_ -in $virtualDistributedSwitchDetails.portgroups.transportType })
If ($virtualDistributedSwitchDetails.transportZones) {
$vdsObject | Add-Member -NotePropertyName 'transportZones' -NotePropertyValue $virtualDistributedSwitchDetails.transportZones
$vdsObject | Add-Member -NotePropertyName 'hostSwitchOperationalMode' -NotePropertyValue $virtualDistributedSwitchDetails.hostSwitchOperationalMode
}
$vdsDetails += $vdsObject
}
$clusters += [pscustomobject]@{
'id' = $id
'datacenter' = $datacenter
'ftt' = $ftt
'isDefault' = $isDefault
'isStretched' = $isStretched
'name' = $name
'vCenterID' = $vCenterID
'primaryDatastoreName' = $primaryDatastoreName
'primaryDatastoreType' = $primaryDatastoreType
'isImageBased' = $isImagedBased
'sourceID' = $sourceID
'vdsDetails' = $vdsDetails
'hosts' = $hostsArray
}
}
$clustersLineIndex++
}
Until ($lineContent -eq '\.')
#Get Cluster and vCenter
LogMessage -type INFO -message "[$jumpboxName] Retrieving Cluster and vCenter Mappings"
$clusterAndVcenterLineNumber = ($psqlContent | Select-String -SimpleMatch "COPY public.cluster_and_vcenter" | Select-Object Line, LineNumber).LineNumber
$clusterAndVcenterLineIndex = $clusterAndVcenterLineNumber
$clusterAndVcenter = @()
Do {
$lineContent = $psqlContent | Select-Object -Index $clusterAndVcenterLineIndex
If ($lineContent -ne '\.') {
$clusterID = $lineContent.split("`t")[0]
$vcenterID = $lineContent.split("`t")[1]
$clusterAndVcenter += [pscustomobject]@{
'clusterID' = $clusterID
'vcenterID' = $vcenterID
}
}
$clusterAndVcenterLineIndex++
}
Until ($lineContent -eq '\.')
#Get Cluster and Domain
LogMessage -type INFO -message "[$jumpboxName] Retrieving Cluster and Domain Mappings"
$clusterAndDomainLineNumber = ($psqlContent | Select-String -SimpleMatch "COPY public.cluster_and_domain" | Select-Object Line, LineNumber).LineNumber
$clusterAndDomainLineIndex = $clusterAndDomainLineNumber
$clusterAndDomain = @()
Do {
$lineContent = $psqlContent | Select-Object -Index $clusterAndDomainLineIndex
If ($lineContent -ne '\.') {
$clusterID = $lineContent.split("`t")[0]
$domainID = $lineContent.split("`t")[1]
$clusterAndDomain += [pscustomobject]@{
'clusterID' = $clusterID
'domainID' = $domainID
}
}
$clusterAndDomainLineIndex++
}
Until ($lineContent -eq '\.')
#Get License Models
LogMessage -type INFO -message "[$jumpboxName] Retrieving Licensing Models"
$licenseModelLineNumber = ($psqlContent | Select-String -SimpleMatch "COPY licensemanager.licensing_info" | Select-Object Line, LineNumber).LineNumber
If ($licenseModelLineNumber) {
$licenseModelLineIndex = $licenseModelLineNumber
$licenseModels = @()
Do {
$lineContent = $psqlContent | Select-Object -Index $licenseModelLineIndex
If ($lineContent -ne '\.') {
$resourceType = $lineContent.split("`t")[1]
$resourceId = $lineContent.split("`t")[2]
$licensingMode = $lineContent.split("`t")[3]
$licenseModels += [pscustomobject]@{
'resourceType' = $resourceType
'resourceId' = $resourceId
'licensingMode' = $licensingMode
}
}
$licenseModelLineIndex++
}
Until ($lineContent -eq '\.')
}
#Get License Keys
LogMessage -type INFO -message "[$jumpboxName] Retrieving License Keys"
$licenseLineNumber = ($psqlContent | Select-String -SimpleMatch "COPY licensemanager.licensekey" | Select-Object Line, LineNumber).LineNumber
$licenseLineIndex = $licenseLineNumber
$licenseKeys = @()
Do {
$lineContent = $psqlContent | Select-Object -Index $licenseLineIndex
If ($lineContent -ne '\.') {
$id = $lineContent.split("`t")[0]
$key = $lineContent.split("`t")[1]
$description = $lineContent.split("`t")[2]
$productType = $lineContent.split("`t")[3]
$licenseKeys += [pscustomobject]@{
'id' = $id
'key' = $key
'description' = $description
'productType' = $productType
}
}
$licenseLineIndex++
}
Until ($lineContent -eq '\.')
If ($sddcManagerObject.version -like "4.4.*") {
LogMessage -type INFO -message "[$jumpboxName] Retrieving PSC Data"
$pscsStartingLineNumber = ($psqlContent | Select-String -SimpleMatch "COPY public.psc (id" | Select-Object Line, LineNumber).LineNumber
$pscsLineIndex = $pscsStartingLineNumber
$pscs = @()
Do {
$lineContent = $psqlContent | Select-Object -Index $pscsLineIndex
If ($lineContent -ne '\.') {
$pscId = $lineContent.split("`t")[0]
$ssoDomain = $lineContent.split("`t")[9]
$pscs += [pscustomobject]@{
'id' = $pscId
'ssoDomain' = $ssoDomain
}
}
$pscsLineIndex ++
}
Until ($lineContent -eq '\.')
$vCentersAndPscsStartingLineNumber = ($psqlContent | Select-String -SimpleMatch "COPY public.vcenter_and_psc" | Select-Object Line, LineNumber).LineNumber
$vCentersAndPscsLineIndex = $vCentersAndPscsStartingLineNumber
$vCentersAndPscs = @()
Do {
$lineContent = $psqlContent | Select-Object -Index $vCentersAndPscsLineIndex
If ($lineContent -ne '\.') {
$vCenterId = $lineContent.split("`t")[0]
$pscId = $lineContent.split("`t")[1]
$vCentersAndPscs += [pscustomobject]@{
'vcenterId' = $vCenterId
'pscId' = $pscId
}
}
$vCentersAndPscsLineIndex ++
}
Until ($lineContent -eq '\.')
}
LogMessage -type INFO -message "[$jumpboxName] Assembling Workload Domain Data"
#GetDomainDetails
$domainsStartingLineNumber = ($psqlContent | Select-String -SimpleMatch "COPY public.domain (id" | Select-Object Line, LineNumber).LineNumber
$domainLineIndex = $domainsStartingLineNumber
$workloadDomains = @()
Do {
$lineContent = $psqlContent | Select-Object -Index $domainLineIndex
If ($lineContent -ne '\.') {
$domainId = $lineContent.split("`t")[0]
$domainName = $lineContent.split("`t")[3]
$domainType = $lineContent.split("`t")[6]
$vCenter = $vCenters | Where-Object { $_.vCenterDomainID -eq $domainId }
$ssoDomain = $lineContent.split("`t")[11]
$vCenterDetails = [pscustomobject]@{
'id' = $vCenter.vCenterID
'version' = $vCenter.vCenterVersion
'fqdn' = $vCenter.vCenterFqdn
'ip' = $vCenter.vCenterIp
'vmname' = $vCenter.vCenterVMname
}
#HostID from hostsAndDomains of first host in domain based on DomainID
$hostID = (($hostsAndDomains | Where-Object { $_.domainID -eq $domainID })[0]).hostId
#PoolID from HostandPools based on HostID
$poolID = ($hostsAndPools | Where-Object { $_.hostId -eq $hostID }).PoolID
#poolName from Networkpools based on PoolID
$poolName = ($networkPools | Where-Object { $_.poolID -eq $poolID }).PoolName
#networks from poolID
$domainNetworks = ($poolsAndNetworks | Where-Object { $_.poolID -eq $poolID }).networkID