Src/Public/Invoke-AsBuiltReport.VMware.ESXi.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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
function Invoke-AsBuiltReport.VMware.ESXi {
    <#
    .SYNOPSIS
        PowerShell script to document the configuration of VMware ESXi servers in Word/HTML/XML/Text formats
    .DESCRIPTION
        Documents the configuration of VMware ESXi servers in Word/HTML/XML/Text formats using PScribo.
    .NOTES
        Version: 1.0.0
        Author: Tim Carman
        Twitter: @tpcarman
        Github: tpcarman
        Credits: Iain Brighton (@iainbrighton) - PScribo module
    .LINK
        https://github.com/AsBuiltReport/AsBuiltReport.VMware.ESXi
    #>


    param (
        [String[]] $Target,
        [PSCredential] $Credential,
        [String] $StylePath
    )

    # Import JSON Configuration for Options and InfoLevel
    $InfoLevel = $ReportConfig.InfoLevel
    $Options = $ReportConfig.Options

    $TextInfo = (Get-Culture).TextInfo

    # If custom style not set, use default style
    if (!$StylePath) {
        & "$PSScriptRoot\..\..\AsBuiltReport.VMware.ESXi.Style.ps1"
    }

    #region Script Functions
    #---------------------------------------------------------------------------------------------#
    # SCRIPT FUNCTIONS #
    #---------------------------------------------------------------------------------------------#

    function Get-VMHostLicense {
        <#
    .SYNOPSIS
    Function to retrieve VMware ESXi product licensing information.
    .DESCRIPTION
    Function to retrieve VMware ESXi product licensing information.
    .NOTES
    Version: 0.1.0
    Author: Tim Carman
    Twitter: @tpcarman
    Github: tpcarman
    .PARAMETER VMHost
    A vSphere ESXi Host objects
    .INPUTS
    System.Management.Automation.PSObject.
    .OUTPUTS
    System.Management.Automation.PSObject.
    .EXAMPLE
    PS> Get-VMHostLicense -VMHost ESXi01
    #>

        [CmdletBinding()][OutputType('System.Management.Automation.PSObject')]

        Param
        (
            [Parameter(Mandatory = $false, ValueFromPipeline = $false)]
            [ValidateNotNullOrEmpty()]
            [PSObject]$vCenter, 
            [PSObject]$VMHost,
            [Parameter(Mandatory = $false, ValueFromPipeline = $false)]
            [Switch]$Licenses
        ) 

        if ($VMHost) {
            $LicenseObject = @()
            $ServiceInstance = Get-View ServiceInstance
            $LicenseManager = Get-View $ServiceInstance.Content.LicenseManager
            #$LicenseManagerAssign = Get-View $LicenseManager.LicenseAssignmentManager
        
            #$VMHostId = $VMHost.Extensiondata.Config.Host.Value
            #$VMHostAssignedLicense = $LicenseManagerAssign.QueryAssignedLicenses($VMHostId)
            $VMHostLicense = $LicenseManager.Licenses
            $VMHostLicenseExpiration = ($VMHostLicense.Properties | Where-Object { $_.Key -eq 'expirationDate' } | Select-Object Value).Value
            if ($VMHostLicense.LicenseKey -and $Options.ShowLicenseKeys) {
                $VMHostLicenseKey = $VMHostLicense.LicenseKey
            } else {
                $VMHostLicenseKey = "*****-*****-*****" + $VMHostLicense.LicenseKey.Substring(17)
            }
            $LicenseObject = [PSCustomObject]@{                               
                Product = $VMHostLicense.Name 
                LicenseKey = $VMHostLicenseKey
                Expiration =
                if ($VMHostLicenseExpiration -eq $null) {
                    "Never" 
                } elseif ($VMHostLicenseExpiration -gt (Get-Date)) {
                    $VMHostLicenseExpiration.ToShortDateString()
                } else {
                    "Expired"
                }
            }
        }        
        Write-Output $LicenseObject
    }

    function Get-VMHostNetworkAdapterCDP {
        <#
    .SYNOPSIS
    Function to retrieve the Network Adapter CDP info of a vSphere host.
    .DESCRIPTION
    Function to retrieve the Network Adapter CDP info of a vSphere host.
    .PARAMETER VMHost
    A vSphere ESXi Host object
    .INPUTS
    System.Management.Automation.PSObject.
    .OUTPUTS
    System.Management.Automation.PSObject.
    .EXAMPLE
    PS> Get-VMHostNetworkAdapterCDP -VMHost ESXi01,ESXi02
    .EXAMPLE
    PS> Get-VMHost ESXi01,ESXi02 | Get-VMHostNetworkAdapterCDP
    #>

        [CmdletBinding()][OutputType('System.Management.Automation.PSObject')]

        Param
        (
            [parameter(Mandatory = $true, ValueFromPipeline = $true)]
            [ValidateNotNullOrEmpty()]
            [PSObject[]]$VMHosts   
        )    

        begin {
            $CDPObject = @()
        }

        process {
            try {
                foreach ($VMHost in $VMHosts) {
                    $ConfigManagerView = Get-View $VMHost.ExtensionData.ConfigManager.NetworkSystem
                    $pNics = $ConfigManagerView.NetworkInfo.Pnic
                    foreach ($pNic in $pNics) {
                        $PhysicalNicHintInfo = $ConfigManagerView.QueryNetworkHint($pNic.Device)
                        $Object = [PSCustomObject]@{                            
                            'VMHost' = $VMHost.ExtensionData.Name
                            'Device' = $pNic.Device
                            'Status' = if ($PhysicalNicHintInfo.ConnectedSwitchPort) {
                                'Connected'
                            } else {
                                'Disconnected'
                            }
                            'SwitchId' = $PhysicalNicHintInfo.ConnectedSwitchPort.DevId
                            'Address' = $PhysicalNicHintInfo.ConnectedSwitchPort.Address
                            'VLAN' = $PhysicalNicHintInfo.ConnectedSwitchPort.Vlan
                            'MTU' = $PhysicalNicHintInfo.ConnectedSwitchPort.Mtu
                            'SystemName' = $PhysicalNicHintInfo.ConnectedSwitchPort.SystemName
                            'Location' = $PhysicalNicHintInfo.ConnectedSwitchPort.Location
                            'HardwarePlatform' = $PhysicalNicHintInfo.ConnectedSwitchPort.HardwarePlatform
                            'SoftwareVersion' = $PhysicalNicHintInfo.ConnectedSwitchPort.SoftwareVersion
                            'ManagementAddress' = $PhysicalNicHintInfo.ConnectedSwitchPort.MgmtAddr
                            'PortId' = $PhysicalNicHintInfo.ConnectedSwitchPort.PortId
                        }
                        $CDPObject += $Object
                    }
                }
            } catch [Exception] {
                throw 'Unable to retrieve CDP info'
            }
        }
        end {
            Write-Output $CDPObject
        }
    }

    function Get-InstallDate {
        $esxcli = Get-EsxCli -VMHost $VMHost -V2
        $thisUUID = $esxcli.system.uuid.get.Invoke()
        $decDate = [Convert]::ToInt32($thisUUID.Split("-")[0], 16)
        $installDate = [timezone]::CurrentTimeZone.ToLocalTime(([datetime]'1/1/1970').AddSeconds($decDate))
        [PSCustomObject][Ordered]@{
            Name = $VMHost.ExtensionData.Name
            InstallDate = $installDate
        }
    }

    function Get-Uptime {
        [CmdletBinding()][OutputType('System.Management.Automation.PSObject')]
        Param (
            [Parameter(Mandatory = $false, ValueFromPipeline = $false)]
            [ValidateNotNullOrEmpty()]
            [PSObject]$VMHost, [PSObject]$VM
        )
        $UptimeObject = @()
        $Date = (Get-Date).ToUniversalTime() 
        If ($VMHost) {
            $UptimeObject = Get-View -ViewType hostsystem -Property Name, Runtime.BootTime -Filter @{
                "Name" = "^$($VMHost.ExtensionData.Name)$"
                "Runtime.ConnectionState" = "connected"
            } | Select-Object Name, @{L = 'UptimeDays'; E = { [math]::round(((($Date) - ($_.Runtime.BootTime)).TotalDays), 2) } }, @{L = 'UptimeHours'; E = { [math]::round(((($Date) - ($_.Runtime.BootTime)).TotalHours), 2) } }, @{L = 'UptimeMinutes'; E = { [math]::round(((($Date) - ($_.Runtime.BootTime)).TotalMinutes), 2) } }
        }

        if ($VM) {
            $UptimeObject = Get-View -ViewType VirtualMachine -Property Name, Runtime.BootTime -Filter @{
                "Name" = "^$($VM.Name)$"
                "Runtime.PowerState" = "poweredOn"
            } | Select-Object Name, @{L = 'UptimeDays'; E = { [math]::round(((($Date) - ($_.Runtime.BootTime)).TotalDays), 2) } }, @{L = 'UptimeHours'; E = { [math]::round(((($Date) - ($_.Runtime.BootTime)).TotalHours), 2) } }, @{L = 'UptimeMinutes'; E = { [math]::round(((($Date) - ($_.Runtime.BootTime)).TotalMinutes), 2) } }
        }
        Write-Output $UptimeObject
    }

    function Get-ESXiBootDevice {
        <#
    .NOTES
    ===========================================================================
        Created by: William Lam
        Organization: VMware
        Blog: www.virtuallyghetto.com
        Twitter: @lamw
    ===========================================================================
    .DESCRIPTION
        This function identifies how an ESXi host was booted up along with its boot
        device (if applicable). This supports both local installation to Auto Deploy as
        well as Boot from SAN.
    .PARAMETER VMHostname
        The name of an individual ESXi host managed by vCenter Server
    .EXAMPLE
        Get-ESXiBootDevice
    .EXAMPLE
        Get-ESXiBootDevice -VMHost esxi-01
    #>

        param(
            [Parameter(Mandatory = $false)][PSObject]$VMHost
        )

        $results = @()
        $esxcli = Get-EsxCli -V2 -VMHost $vmhost
        $bootDetails = $esxcli.system.boot.device.get.Invoke()

        # Check to see if ESXi booted over the network
        $networkBoot = $false
        if ($bootDetails.BootNIC) {
            $networkBoot = $true
            $bootDevice = $bootDetails.BootNIC
        } elseif ($bootDetails.StatelessBootNIC) {
            $networkBoot = $true
            $bootDevice = $bootDetails.StatelessBootNIC
        }

        # If ESXi booted over network, check to see if deployment
        # is Stateless, Stateless w/Caching or Stateful
        if ($networkBoot) {
            $option = $esxcli.system.settings.advanced.list.CreateArgs()
            $option.option = "/UserVars/ImageCachedSystem"
            try {
                $optionValue = $esxcli.system.settings.advanced.list.Invoke($option)
            } catch {
                $bootType = "Stateless"
            }
            $bootType = $optionValue.StringValue
        }

        # Loop through all storage devices to identify boot device
        $devices = $esxcli.storage.core.device.list.Invoke()
        $foundBootDevice = $false
        foreach ($device in $devices) {
            if ($device.IsBootDevice -eq $true) {
                $foundBootDevice = $true

                if ($device.IsLocal -eq $true -and $networkBoot -and $bootType -ne "Stateful") {
                    $bootType = "Stateless Caching"
                } elseif ($device.IsLocal -eq $true -and $networkBoot -eq $false) {
                    $bootType = "Local"
                } elseif ($device.IsLocal -eq $false -and $networkBoot -eq $false) {
                    $bootType = "Remote"
                }

                $bootDevice = $device.Device
                $bootModel = $device.Model
                $bootVendor = $device.VEndor
                $bootSize = $device.Size
                $bootIsSAS = $TextInfo.ToTitleCase($device.IsSAS)
                $bootIsSSD = $TextInfo.ToTitleCase($device.IsSSD)
                $bootIsUSB = $TextInfo.ToTitleCase($device.IsUSB)
            }
        }

        # Pure Stateless (e.g. No USB or Disk for boot)
        if ($networkBoot -and $foundBootDevice -eq $false) {
            $bootModel = "N/A"
            $bootVendor = "N/A"
            $bootSize = "N/A"
            $bootIsSAS = "N/A"
            $bootIsSSD = "N/A"
            $bootIsUSB = "N/A"
        }

        $tmp = [PSCustomObject]@{
            Host = $($VMHost.ExtensionData.Name);
            Device = $bootDevice;
            BootType = $bootType;
            Vendor = $bootVendor;
            Model = $bootModel;
            SizeMB = $bootSize;
            IsSAS = $bootIsSAS;
            IsSSD = $bootIsSSD;
            IsUSB = $bootIsUSB;
        }
        $results += $tmp
        $results
    }

    function Get-ScsiDeviceDetail {
        <#
        .SYNOPSIS
        Helper function to return Scsi device information for a specific host and a specific datastore.
        .PARAMETER VMHosts
        This parameter accepts a list of host objects returned from the Get-VMHost cmdlet
        .PARAMETER VMHostMoRef
        This parameter specifies, by MoRef Id, the specific host of interest from with the $VMHosts array.
        .PARAMETER DatastoreDiskName
        This parameter specifies, by disk name, the specific datastore of interest.
        .EXAMPLE
        $VMHosts = Get-VMHost
        Get-ScsiDeviceDetail -AllVMHosts $VMHosts -VMHostMoRef 'HostSystem-host-131' -DatastoreDiskName 'naa.6005076801810082480000000001d9fe'
        DisplayName : IBM Fibre Channel Disk (naa.6005076801810082480000000001d9fe)
        Ssd : False
        LocalDisk : False
        CanonicalName : naa.6005076801810082480000000001d9fe
        Vendor : IBM
        Model : 2145
        Multipath Policy : Round Robin
        CapacityGB : 512
        .NOTES
        Author: Ryan Kowalewski
    #>


        [CmdLetBinding()]
        param (
            [Parameter(Mandatory = $true)]
            $VMHosts,
            [Parameter(Mandatory = $true)]
            $VMHostMoRef,
            [Parameter(Mandatory = $true)]
            $DatastoreDiskName
        )

        $VMHostObj = $VMHosts | Where-Object { $_.Id -eq $VMHostMoRef }
        $ScsiDisk = $VMHostObj.ExtensionData.Config.StorageDevice.ScsiLun | Where-Object {
            $_.CanonicalName -eq $DatastoreDiskName
        }
        $Multipath = $VMHostObj.ExtensionData.Config.StorageDevice.MultipathInfo.Lun | Where-Object {
            $_.Lun -eq $ScsiDisk.Key
        }
        $CapacityGB = [math]::Round((($ScsiDisk.Capacity.BlockSize * $ScsiDisk.Capacity.Block) / 1024 / 1024 / 1024), 2)

        [PSCustomObject]@{
            'DisplayName' = $ScsiDisk.DisplayName
            'Ssd' = $ScsiDisk.Ssd
            'LocalDisk' = $ScsiDisk.LocalDisk
            'CanonicalName' = $ScsiDisk.CanonicalName
            'Vendor' = $ScsiDisk.Vendor
            'Model' = $ScsiDisk.Model
            'MultipathPolicy' = Switch ($Multipath.Policy.Policy) {
                'VMW_PSP_RR' { 'Round Robin' }
                'VMW_PSP_FIXED' { 'Fixed' }
                'VMW_PSP_MRU' { 'Most Recently Used' }
                default { $Multipath.Policy.Policy }
            }
            'Paths' = ($Multipath.Path).Count
            'CapacityGB' = $CapacityGB
        }
    }

    Function Get-PciDeviceDetail {
        <#
    .SYNOPSIS
    Helper function to return PCI Devices Drivers & Firmware information for a specific host.
    .PARAMETER Server
    vCenter VISession object.
    .PARAMETER esxcli
    Esxcli session object associated to the host.
    .EXAMPLE
    $Credentials = Get-Credential
    $Server = Connect-VIServer -Server vcenter01.example.com -Credentials $Credentials
    $VMHost = Get-VMHost -Server $Server -Name esx01.example.com
    $esxcli = Get-EsxCli -Server $Server -VMHost $VMHost -V2
    Get-PciDeviceDetail -Server $vCenter -esxcli $esxcli
    VMkernel Name : vmhba0
    Device Name : Sunrise Point-LP AHCI Controller
    Driver : vmw_ahci
    Driver Version : 1.0.0-34vmw.650.0.14.5146846
    Firmware Version : NA
    VIB Name : vmw-ahci
    VIB Version : 1.0.0-34vmw.650.0.14.5146846
    .NOTES
    Author: Erwan Quelin heavily based on the work of the vDocumentation team - https://github.com/arielsanchezmora/vDocumentation/blob/master/powershell/vDocumentation/Public/Get-ESXIODevice.ps1
    #>

        [CmdletBinding()]
        Param (
            [Parameter(Mandatory = $true)]
            $Server,
            [Parameter(Mandatory = $true)]
            $esxcli
        )
        Begin { }
    
        Process {
            # Set default results
            $firmwareVersion = "N/A"
            $vibName = "N/A"
            $driverVib = @{
                Name = "N/A"
                Version = "N/A"
            }
            $pciDevices = $esxcli.hardware.pci.list.Invoke() | Where-Object { $_.VMkernelName -like "vmhba*" -or $_.VMkernelName -like "vmnic*" -or $_.VMkernelName -like "vmgfx*" } | Sort-Object -Property VMkernelName 
            $nicList = $esxcli.network.nic.list.Invoke() | Sort-Object Name
            #$fcoeAdapterList = $esxcli.fcoe.adapter.list.Invoke().PhysicalNIC # Get list of vmnics used for FCoE, because we don't want those vmnics here.
            foreach ($pciDevice in $pciDevices) {
                $driverVersion = $esxcli.system.module.get.Invoke(@{module = $pciDevice.ModuleName }) | Select-Object -ExpandProperty Version
                # Get NIC Firmware version
                #if (($pciDevice.VMkernelName -like 'vmnic*') -and ($fcoeAdapterList -notcontains $pciDevice.VMkernelName) -and ($nicList.Name -contains $pciDevice.VMkernelName) ) {
                if (($pciDevice.VMkernelName -like 'vmnic*') -and ($nicList.Name -contains $pciDevice.VMkernelName) ) {   
                    $vmnicDetail = $esxcli.network.nic.get.Invoke(@{nicname = $pciDevice.VMkernelName })
                    $firmwareVersion = $vmnicDetail.DriverInfo.FirmwareVersion
                    # Get NIC driver VIB package version
                    $driverVib = $esxcli.software.vib.list.Invoke() | Select-Object -Property Name, Version | Where-Object { $_.Name -eq $vmnicDetail.DriverInfo.Driver -or $_.Name -eq "net-" + $vmnicDetail.DriverInfo.Driver -or $_.Name -eq "net55-" + $vmnicDetail.DriverInfo.Driver }
                    <#
                    If HP Smart Array vmhba* (scsi-hpsa driver) then get Firmware version
                    else skip if VMkernnel is vmhba*. Can't get HBA Firmware from
                    Powercli at the moment only through SSH or using Putty Plink+PowerCli.
                    #>

                } elseif ($pciDevice.VMkernelName -like 'vmhba*') {
                    if ($pciDevice.DeviceName -match "smart array") {
                        $hpsa = $vmhost.ExtensionData.Runtime.HealthSystemRuntime.SystemHealthInfo.NumericSensorInfo | Where-Object { $_.Name -match "HP Smart Array" }
                        if ($hpsa) {
                            $firmwareVersion = (($hpsa.Name -split "firmware")[1]).Trim()
                        }
                    }
                    # Get HBA driver VIB package version
                    $vibName = $pciDevice.ModuleName -replace "_", "-"
                    $driverVib = $esxcli.software.vib.list.Invoke() | Select-Object -Property Name, Version | Where-Object { $_.Name -eq "scsi-" + $VibName -or $_.Name -eq "sata-" + $VibName -or $_.Name -eq $VibName }
                }
                # Output collected data
                [PSCustomObject]@{
                    'VMkernel Name' = $pciDevice.VMkernelName
                    'Device Name' = $pciDevice.DeviceName
                    'Driver' = $pciDevice.ModuleName
                    'Driver Version' = $driverVersion
                    'Firmware Version' = $firmwareVersion
                    'VIB Name' = $driverVib.Name
                    'VIB Version' = $driverVib.Version
                }
            } 
        }
        End { }
    }
    #endregion Script Functions

    #region Script Body
    #---------------------------------------------------------------------------------------------#
    # SCRIPT BODY #
    #---------------------------------------------------------------------------------------------#
    # Connect to ESXi Server using supplied credentials
    foreach ($VIServer in $Target) { 
        try {
            $ESXi = Connect-VIServer $VIServer -Credential $Credential -ErrorAction Stop
        } catch {
            Write-Error $_
        }
        #region Generate ESXi report
        if ($ESXi) {
            # Create a lookup hashtable to quickly link VM MoRefs to Names
            # Exclude VMware Site Recovery Manager placeholder VMs
            $VMs = Get-VM -Server $ESXi | Where-Object {
                $_.ExtensionData.Config.ManagedBy.ExtensionKey -notlike 'com.vmware.vcDr*'
            } | Sort-Object Name
            $VMLookup = @{ }
            foreach ($VM in $VMs) {
                $VMLookup.($VM.Id) = $VM.Name
            }

            # Create a lookup hashtable to link Host MoRefs to Names
            # Exclude VMware HCX hosts and ESX/ESXi versions prior to vSphere 5.0 from VMHost lookup
            $VMHosts = Get-VMHost -Server $ESXi | Where-Object { $_.Model -notlike "*VMware Mobility Platform" -and $_.Version -gt 5 } | Sort-Object Name
            $VMHostLookup = @{ }
            foreach ($VMHost in $VMHosts) {
                $VMHostLookup.($VMHost.Id) = $VMHost.ExtensionData.Name
            }

            # Create a lookup hashtable to link Datastore MoRefs to Names
            $Datastores = Get-Datastore -Server $ESXi | Where-Object { ($_.State -eq 'Available') -and ($_.CapacityGB -gt 0) } | Sort-Object Name
            $DatastoreLookup = @{ }
            foreach ($Datastore in $Datastores) {
                $DatastoreLookup.($Datastore.Id) = $Datastore.Name
            }

            # Create a lookup hashtable to link VDS Portgroups MoRefs to Names
            $VDPortGroups = Get-VDPortgroup -Server $ESXi | Sort-Object Name
            $VDPortGroupLookup = @{ }
            foreach ($VDPortGroup in $VDPortGroups) {
                $VDPortGroupLookup.($VDPortGroup.Key) = $VDPortGroup.Name
            }

            if ($InfoLevel.VMHost -ge 1) {
                if ($VMHosts) {
                    #region Hosts Section
                    Section -Style Heading1 $($VMHost.ExtensionData.Name) {
                        Paragraph "The following sections detail the configuration of VMware ESXi host $($VMHost.ExtensionData.Name)."
                        #region ESXi Host Detailed Information
                        foreach ($VMHost in ($VMHosts | Where-Object { $_.ConnectionState -eq 'Connected' -or $_.ConnectionState -eq 'Maintenance' })) {        
                            ### TODO: Host Certificate, Swap File Location
                            #region ESXi Host Hardware Section
                            Section -Style Heading2 'Hardware' {
                                Paragraph "The following section details the host hardware configuration for $($VMHost.ExtensionData.Name)."
                                BlankLine

                                #region ESXi Host Specifications
                                $VMHostUptime = Get-Uptime -VMHost $VMHost
                                $esxcli = Get-EsxCli -VMHost $VMHost -V2
                                $VMHostHardware = Get-VMHostHardware -VMHost $VMHost
                                $VMHostLicense = Get-VMHostLicense -VMHost $VMHost
                                $ScratchLocation = Get-AdvancedSetting -Entity $VMHost | Where-Object { $_.Name -eq 'ScratchConfig.CurrentScratchLocation' }
                                $VMHostDetail = [PSCustomObject]@{
                                    'Host' = $VMHost.ExtensionData.Name
                                    'Connection State' = Switch ($VMHost.ConnectionState) {
                                        'NotResponding' { 'Not Responding' }
                                        default { $VMHost.ConnectionState }
                                    }
                                    'ID' = $VMHost.Id
                                    'Manufacturer' = $VMHost.Manufacturer
                                    'Model' = $VMHost.Model
                                    'Serial Number' = $VMHostHardware.SerialNumber 
                                    'Asset Tag' = Switch ($VMHostHardware.AssetTag) {
                                        '' { 'Unknown' }
                                        default { $VMHostHardware.AssetTag }
                                    }
                                    'Processor Type' = $VMHost.Processortype
                                    'HyperThreading' = Switch ($VMHost.HyperthreadingActive) {
                                        $true { 'Enabled' }
                                        $false { 'Disabled' }
                                    }
                                    'Number of CPU Sockets' = $VMHost.ExtensionData.Hardware.CpuInfo.NumCpuPackages 
                                    'Number of CPU Cores' = $VMHost.ExtensionData.Hardware.CpuInfo.NumCpuCores 
                                    'Number of CPU Threads' = $VMHost.ExtensionData.Hardware.CpuInfo.NumCpuThreads
                                    'CPU Total / Used' = "$([math]::Round(($VMHost.CpuTotalMhz) / 1000, 2)) GHz / $([math]::Round(($VMHost.CpuUsageMhz) / 1000, 2)) GHz"
                                    'Memory Total / Used' = "$([math]::Round($VMHost.MemoryTotalGB, 2)) GB / $([math]::Round($VMHost.MemoryUsageGB, 2)) GB"
                                    'NUMA Nodes' = $VMHost.ExtensionData.Hardware.NumaInfo.NumNodes 
                                    'Number of NICs' = $VMHostHardware.NicCount 
                                    'Number of Datastores' = $VMHost.ExtensionData.Datastore.Count 
                                    'Number of VMs' = $VMHost.ExtensionData.VM.Count 
                                    'Power Management Policy' = $VMHost.ExtensionData.Hardware.CpuPowerManagementInfo.CurrentPolicy 
                                    'Scratch Location' = $ScratchLocation.Value 
                                    'Bios Version' = $VMHost.ExtensionData.Hardware.BiosInfo.BiosVersion 
                                    'Bios Release Date' = $VMHost.ExtensionData.Hardware.BiosInfo.ReleaseDate 
                                    'ESXi Version' = $VMHost.Version 
                                    'ESXi Build' = $VMHost.build 
                                    'Product' = $VMHostLicense.Product -join ', '
                                    'License Key' = $VMHostLicense.LicenseKey
                                    'License Expiration' = $VMHostLicense.Expiration 
                                    'Boot Time' = ($VMHost.ExtensionData.Runtime.Boottime).ToLocalTime()
                                    'Uptime Days' = $VMHostUptime.UptimeDays
                                }
                                if ($Healthcheck.VMHost.ConnectionState) {
                                    $VMHostDetail | Where-Object { $_.'Connection State' -eq 'Maintenance' } | Set-Style -Style Warning -Property 'Connection State'
                                }
                                if ($Healthcheck.VMHost.HyperThreading) {
                                    $VMHostDetail | Where-Object { $_.'HyperThreading' -eq 'Disabled' } | Set-Style -Style Warning -Property 'Disabled'
                                }
                                if ($Healthcheck.VMHost.Licensing) {
                                    $VMHostDetail | Where-Object { $_.'Product' -like '*Evaluation*' } | Set-Style -Style Warning -Property 'Product'
                                    $VMHostDetail | Where-Object { $_.'License Key' -like '*-00000-00000' } | Set-Style -Style Warning -Property 'License Key'
                                    $VMHostDetail | Where-Object { $_.'License Expiration' -eq 'Expired' } | Set-Style -Style Critical -Property 'License Expiration'
                                }
                                if ($Healthcheck.VMHost.ScratchLocation) {
                                    $VMHostDetail | Where-Object { $_.'Scratch Location' -eq '/tmp/scratch' } | Set-Style -Style Warning -Property 'Scratch Location'
                                }
                                if ($Healthcheck.VMHost.UpTimeDays) {
                                    $VMHostDetail | Where-Object { $_.'Uptime Days' -ge 275 -and $_.'Uptime Days' -lt 365 } | Set-Style -Style Warning -Property 'Uptime Days'
                                    $VMHostDetail | Where-Object { $_.'Uptime Days' -ge 365 } | Set-Style -Style Critical -Property 'Uptime Days'
                                }
                                $VMHostDetail | Table -Name "$($VMHost.ExtensionData.Name) ESXi Host Detailed Information" -List -ColumnWidths 50, 50 
                                #endregion ESXi Host Specifications

                                #region ESXi Host Boot Device
                                Section -Style Heading3 'Boot Device' {
                                    $ESXiBootDevice = Get-ESXiBootDevice -VMHost $VMHost
                                    $VMHostBootDevice = [PSCustomObject]@{
                                        'Host' = $ESXiBootDevice.Host
                                        'Device' = $ESXiBootDevice.Device
                                        'Boot Type' = $ESXiBootDevice.BootType
                                        'Vendor' = $ESXiBootDevice.Vendor
                                        'Model' = $ESXiBootDevice.Model
                                        'Size' = "$([math]::Round($ESXiBootDevice.SizeMB / 1024, 2)) GB"
                                        'Is SAS' = $ESXiBootDevice.IsSAS
                                        'Is SSD' = $ESXiBootDevice.IsSSD
                                        'Is USB' = $ESXiBootDevice.IsUSB
                                    }
                                    $VMHostBootDevice | Table -Name "$($VMHost.ExtensionData.Name) Boot Device" -List -ColumnWidths 50, 50 
                                }
                                #endregion ESXi Host Boot Devices

                                #region ESXi Host PCI Devices
                                Section -Style Heading3 'PCI Devices' {
                                    $PciHardwareDevices = $esxcli.hardware.pci.list.Invoke() | Where-Object { $_.VMkernelName -like "vmhba*" -OR $_.VMkernelName -like "vmnic*" -OR $_.VMkernelName -like "vmgfx*" } 
                                    $VMHostPciDevices = foreach ($PciHardwareDevice in $PciHardwareDevices) {
                                        [PSCustomObject]@{
                                            'VMkernel Name' = $PciHardwareDevice.VMkernelName 
                                            'PCI Address' = $PciHardwareDevice.Address 
                                            'Device Class' = $PciHardwareDevice.DeviceClassName 
                                            'Device Name' = $PciHardwareDevice.DeviceName 
                                            'Vendor Name' = $PciHardwareDevice.VendorName 
                                            'Slot Description' = $PciHardwareDevice.SlotDescription
                                        }
                                    }
                                    $VMHostPciDevices | Sort-Object 'VMkernel Name' | Table -Name "$($VMHost.ExtensionData.Name) PCI Devices" 
                                }
                                #endregion ESXi Host PCI Devices
                    
                                #region ESXi Host PCI Devices Drivers & Firmware
                                Section -Style Heading3 'PCI Devices Drivers & Firmware' {
                                    $VMHostPciDevicesDetails = Get-PciDeviceDetail -Server $VMHost -esxcli $esxcli 
                                    $VMHostPciDevicesDetails | Sort-Object 'VMkernel Name' | Table -Name "$($VMHost.ExtensionData.Name) PCI Devices Drivers & Firmware" 
                                }
                                #endregion ESXi Host PCI Devices Drivers & Firmware
                                #>
                            }
                            #endregion ESXi Host Hardware Section

                            #region ESXi Host System Section
                            Section -Style Heading2 'System' {
                                Paragraph "The following section details the host system configuration for $($VMHost.ExtensionData.Name)."
                                #region ESXi Host Image Profile Information
                                Section -Style Heading3 'Image Profile' {
                                    $installdate = Get-InstallDate
                                    $esxcli = Get-EsxCli -VMHost $VMHost -V2
                                    $ImageProfile = $esxcli.software.profile.get.Invoke()
                                    $SecurityProfile = [PSCustomObject]@{
                                        'Image Profile' = $ImageProfile.Name
                                        'Vendor' = $ImageProfile.Vendor
                                        'Installation Date' = $InstallDate.InstallDate
                                    }
                                    $SecurityProfile | Table -Name "$($VMHost.ExtensionData.Name) Image Profile" -ColumnWidths 50, 25, 25 
                                }
                                #endregion ESXi Host Image Profile Information

                                #region ESXi Host Time Configuration
                                Section -Style Heading3 'Time Configuration' {
                                    $VMHostTimeSettings = [PSCustomObject]@{
                                        'Time Zone' = $VMHost.timezone
                                        'NTP Service' = Switch ((Get-VMHostService -VMHost $VMHost | Where-Object { $_.key -eq 'ntpd' }).Running) {
                                            $true { 'Running' }
                                            $false { 'Stopped' }
                                        }
                                        'NTP Server(s)' = (Get-VMHostNtpServer -VMHost $VMHost | Sort-Object) -join ', '
                                    }
                                    if ($Healthcheck.VMHost.NTP) {
                                        $VMHostTimeSettings | Where-Object { $_.'NTP Service' -eq 'Stopped' } | Set-Style -Style Critical -Property 'NTP Service'
                                    }
                                    $VMHostTimeSettings | Table -Name "$($VMHost.ExtensionData.Name) Time Configuration" -ColumnWidths 30, 30, 40
                                }
                                #endregion ESXi Host Time Configuration

                                #region ESXi Host Syslog Configuration
                                $SyslogConfig = $VMHost | Get-VMHostSysLogServer
                                if ($SyslogConfig) {
                                    Section -Style Heading3 'Syslog Configuration' {
                                        ### TODO: Syslog Rotate & Size, Log Directory (Adv Settings)
                                        $SyslogConfig = $SyslogConfig | Select-Object @{L = 'SysLog Server'; E = { $_.Host } }, Port
                                        $SyslogConfig | Table -Name "$($VMHost.ExtensionData.Name) Syslog Configuration" -ColumnWidths 50, 50 
                                    }
                                }
                                #endregion ESXi Host Syslog Configuration

                                #region ESXi Host Comprehensive Information Section
                                if ($InfoLevel.VMHost -ge 5) {
                                    #region ESXi Host Advanced System Settings
                                    Section -Style Heading3 'Advanced System Settings' {
                                        $AdvSettings = $VMHost | Get-AdvancedSetting | Select-Object Name, Value
                                        $AdvSettings | Sort-Object Name | Table -Name "$($VMHost.ExtensionData.Name) Advanced System Settings" -ColumnWidths 50, 50 
                                    }
                                    #endregion ESXi Host Advanced System Settings

                                    #region ESXi Host Software VIBs
                                    Section -Style Heading3 'Software VIBs' {
                                        $esxcli = Get-EsxCli -VMHost $VMHost -V2
                                        $VMHostVibs = $esxcli.software.vib.list.Invoke()
                                        $VMHostVibs = foreach ($VMHostVib in $VMHostVibs) {
                                            [PSCustomObject]@{
                                                'VIB' = $VMHostVib.Name
                                                'ID' = $VMHostVib.Id
                                                'Version' = $VMHostVib.Version
                                                'Acceptance Level' = $VMHostVib.AcceptanceLevel
                                                'Creation Date' = $VMHostVib.CreationDate
                                                'Install Date' = $VMHostVib.InstallDate
                                            }
                                        } 
                                        $VMHostVibs | Sort-Object 'Install Date' -Descending | Table -Name "$($VMHost.ExtensionData.Name) Software VIBs" -ColumnWidths 15, 25, 15, 15, 15, 15
                                    }
                                    #endregion ESXi Host Software VIBs
                                }
                                #endregion ESXi Host Comprehensive Information Section
                            }
                            #endregion ESXi Host System Section

                            #region ESXi Host Storage Section
                            Section -Style Heading2 'Storage' {
                                Paragraph "The following section details the host storage configuration for $($VMHost.ExtensionData.Name)."
                                
                                #region Datastore Section
                                # Currently there is no Datastore InfoLevel 1
                                if ($InfoLevel.Datastore -ge 2) {
                                    if ($Datastores) {
                                        Section -Style Heading3 'Datastores' {
                                            #region Datastore Infomative Information
                                            if ($InfoLevel.Datastore -eq 2) {
                                                $DatastoreInfo = foreach ($Datastore in $Datastores) {
                                                    [PSCustomObject]@{
                                                        'Datastore' = $Datastore.Name
                                                        'Type' = $Datastore.Type
                                                        'Version' = Switch ($Datastore.FileSystemVersion) {
                                                            $null { '--' }
                                                            default { $Datastore.FileSystemVersion }
                                                        }
                                                        '# of VMs' = $Datastore.ExtensionData.VM.Count
                                                        'Total Capacity GB' = [math]::Round($Datastore.CapacityGB, 2)
                                                        'Used Capacity GB' = [math]::Round((($Datastore.CapacityGB) - ($Datastore.FreeSpaceGB)), 2)
                                                        'Free Space GB' = [math]::Round($Datastore.FreeSpaceGB, 2)
                                                        '% Used' = [math]::Round((100 - (($Datastore.FreeSpaceGB) / ($Datastore.CapacityGB) * 100)), 2)
                                                    }
                                                }
                                                if ($Healthcheck.Datastore.CapacityUtilization) {
                                                    $DatastoreInfo | Where-Object { $_.'% Used' -ge 90 } | Set-Style -Style Critical -Property '% Used'
                                                    $DatastoreInfo | Where-Object { $_.'% Used' -ge 75 -and $_.'% Used' -lt 90 } | Set-Style -Style Warning -Property '% Used'
                                                }
                                                $DatastoreInfo | Sort-Object Datastore | Table -Name 'Datastore Information'
                                            }
                                            #endregion Datastore Informative Information

                                            #region Datastore Detailed Information
                                            if ($InfoLevel.Datastore -ge 3) {
                                                foreach ($Datastore in $Datastores) {
                                                    #region Datastore Section
                                                    Section -Style Heading4 $Datastore.Name {                                
                                                        $DatastoreDetail = [PSCustomObject]@{
                                                            'Datastore' = $Datastore.Name
                                                            'ID' = $Datastore.Id
                                                            'Type' = $Datastore.Type
                                                            'Version' = Switch ($Datastore.FileSystemVersion) {
                                                                $null { '--' }
                                                                default { $Datastore.FileSystemVersion }
                                                            }
                                                            'State' = $Datastore.State
                                                            'Number of VMs' = $Datastore.ExtensionData.VM.Count
                                                            'Storage I/O Control' = Switch ($Datastore.StorageIOControlEnabled) {
                                                                $true { 'Enabled' }
                                                                $false { 'Disabled' }
                                                            }
                                                            'Congestion Threshold' = Switch ($Datastore.CongestionThresholdMillisecond) {
                                                                $null { '--' }
                                                                default { "$($Datastore.CongestionThresholdMillisecond) ms" }
                                                            }
                                                            'Total Capacity' = "$([math]::Round($Datastore.CapacityGB, 2)) GB"
                                                            'Used Capacity' = "$([math]::Round((($Datastore.CapacityGB) - ($Datastore.FreeSpaceGB)), 2)) GB"
                                                            'Free Space' = "$([math]::Round($Datastore.FreeSpaceGB, 2)) GB"
                                                            '% Used' = [math]::Round((100 - (($Datastore.FreeSpaceGB) / ($Datastore.CapacityGB) * 100)), 2)
                                                        }
                                                        if ($Healthcheck.Datastore.CapacityUtilization) {
                                                            $DatastoreDetail | Where-Object { $_.'% Used' -ge 90 } | Set-Style -Style Critical -Property '% Used'
                                                            $DatastoreDetail | Where-Object { $_.'% Used' -ge 75 -and 
                                                                $_.'% Used' -lt 90 } | Set-Style -Style Warning -Property '% Used'
                                                        }
                        
                                                        #region Datastore Advanced Detailed Information
                                                        if ($InfoLevel.Datastore -ge 4) {
                                                            $MemberProps = @{
                                                                'InputObject' = $DatastoreDetail
                                                                'MemberType' = 'NoteProperty'
                                                            }
                                                            $DatastoreVMs = foreach ($DatastoreVM in $Datastore.ExtensionData.VM) {
                                                                $VMLookup."$($DatastoreVM.Type)-$($DatastoreVM.Value)"
                                                            }
                                                            Add-Member @MemberProps -Name 'Virtual Machines' -Value (($DatastoreVMs | Sort-Object) -join ', ')
                                                        }
                                                        #endregion Datastore Advanced Detailed Information

                                                        $DatastoreDetail | Sort-Object Datacenter, Datastore | Table -List -Name 'Datastore Specifications' -ColumnWidths 50, 50

                                                        # Get VMFS volumes. Ignore local SCSILuns.
                                                        if (($Datastore.Type -eq 'VMFS') -and ($Datastore.ExtensionData.Info.Vmfs.Local -eq $false)) {
                                                            #region SCSI LUN Information Section
                                                            Section -Style Heading4 'SCSI LUN Information' {
                                                                $ScsiLuns = foreach ($DatastoreHost in $Datastore.ExtensionData.Host.Key) {
                                                                    $DiskName = $Datastore.ExtensionData.Info.Vmfs.Extent.DiskName
                                                                    $ScsiDeviceDetailProps = @{
                                                                        'VMHosts' = $VMHosts
                                                                        'VMHostMoRef' = "$($DatastoreHost.Type)-$($DatastoreHost.Value)"
                                                                        'DatastoreDiskName' = $DiskName
                                                                    }
                                                                    $ScsiDeviceDetail = Get-ScsiDeviceDetail @ScsiDeviceDetailProps

                                                                    [PSCustomObject]@{
                                                                        'Host' = $VMHostLookup."$($DatastoreHost.Type)-$($DatastoreHost.Value)"
                                                                        'Canonical Name' = $DiskName
                                                                        'Capacity GB' = $ScsiDeviceDetail.CapacityGB
                                                                        'Vendor' = $ScsiDeviceDetail.Vendor
                                                                        'Model' = $ScsiDeviceDetail.Model
                                                                        'Is SSD' = $ScsiDeviceDetail.Ssd
                                                                        'Multipath Policy' = $ScsiDeviceDetail.MultipathPolicy
                                                                        'Paths' = $ScsiDeviceDetail.Paths
                                                                    }
                                                                }
                                                                $ScsiLuns | Sort-Object Host | Table -Name 'SCSI LUN Information'
                                                            }
                                                            #endregion SCSI LUN Information Section
                                                        }
                                                    }
                                                    #endregion Datastore Section
                                                }
                                            }
                                            #endregion Datastore Detailed Information
                                        }
                                    }
                                }
                                #endregion Datastore Section

                                #region ESXi Host Storage Adapter Information
                                $VMHostHbas = $VMHost | Get-VMHostHba | Sort-Object Device
                                if ($VMHostHbas) {
                                    #region ESXi Host Storage Adapters Section
                                    Section -Style Heading3 'Storage Adapters' {
                                        foreach ($VMHostHba in $VMHostHbas) {
                                            $Target = ((Get-View $VMHostHba.VMhost).Config.StorageDevice.ScsiTopology.Adapter | Where-Object { $_.Adapter -eq $VMHostHba.Key }).Target
                                            $LUNs = Get-ScsiLun -Hba $VMHostHba -LunType "disk" -ErrorAction SilentlyContinue
                                            $Paths = ($Target | foreach { $_.Lun.Count } | Measure-Object -Sum)
                                            Section -Style Heading4 "$($VMHostHba.Device)" {
                                                $VMHostStorageAdapter = [PSCustomObject]@{
                                                    'Adapter' = $VMHostHba.Device
                                                    'Type' = Switch ($VMHostHba.Type) {
                                                        'FibreChannel' { 'Fibre Channel' }
                                                        'IScsi' { 'iSCSI' }
                                                        'ParallelScsi' { 'Parallel SCSI' }
                                                        default { $TextInfo.ToTitleCase($VMHostHba.Type) }
                                                    }
                                                    'Model' = $VMHostHba.Model
                                                    'Status' = $TextInfo.ToTitleCase($VMHostHba.Status)
                                                    'Targets' = $Target.Count
                                                    'Devices' = $LUNs.Count
                                                    'Paths' = $Paths.Sum
                                                }
                                                $MemberProps = @{
                                                    'InputObject' = $VMHostStorageAdapter
                                                    'MemberType' = 'NoteProperty'
                                                }
                                                if ($VMHostStorageAdapter.Type -eq 'iSCSI') {
                                                    $iScsiAuthenticationMethod = Switch ($VMHostHba.ExtensionData.AuthenticationProperties.ChapAuthenticationType) {
                                                        'chapProhibited' { 'None' }
                                                        'chapPreferred' { 'Use unidirectional CHAP unless prohibited by target' }
                                                        'chapDiscouraged' { 'Use unidirectional CHAP if required by target' }
                                                        'chapRequired' { 
                                                            Switch ($VMHostHba.ExtensionData.AuthenticationProperties.MutualChapAuthenticationType) {
                                                                'chapProhibited' { 'Use unidirectional CHAP' }
                                                                'chapRequired' { 'Use bidirectional CHAP' }
                                                            } 
                                                        }
                                                        default { $VMHostHba.ExtensionData.AuthenticationProperties.ChapAuthenticationType }
                                                    }
                                                    Add-Member @MemberProps -Name 'iSCSI Name' -Value $VMHostHba.IScsiName
                                                    if ($VMHostHba.IScsiAlias) {
                                                        Add-Member @MemberProps -Name 'iSCSI Alias' -Value $VMHostHba.IScsiAlias
                                                    } else {
                                                        Add-Member @MemberProps -Name 'iSCSI Alias' -Value '--'
                                                    }
                                                    if ($VMHostHba.CurrentSpeedMb) {
                                                        Add-Member @MemberProps -Name 'Speed' -Value "$($VMHostHba.CurrentSpeedMb) Mb"
                                                    } else {
                                                        Add-Member @MemberProps -Name 'Speed' -Value '--'
                                                    }
                                                    if ($VMHostHba.ExtensionData.ConfiguredSendTarget) {
                                                        Add-Member @MemberProps -Name 'Dynamic Discovery' -Value (($VMHostHba.ExtensionData.ConfiguredSendTarget | ForEach-Object { "$($_.Address)" + ":" + "$($_.Port)" }) -join [Environment]::NewLine)
                                                    } else {
                                                        Add-Member @MemberProps -Name 'Dynamic Discovery' -Value '--'
                                                    }
                                                    if ($VMHostHba.ExtensionData.ConfiguredStaticTarget) {
                                                        Add-Member @MemberProps -Name 'Static Discovery' -Value (($VMHostHba.ExtensionData.ConfiguredStaticTarget | ForEach-Object { "$($_.Address)" + ":" + "$($_.Port)" + " " + "$($_.IScsiName)" }) -join [Environment]::NewLine)
                                                    } else {
                                                        Add-Member @MemberProps -Name 'Static Discovery' -Value '--'
                                                    }
                                                    if ($iScsiAuthenticationMethod -eq 'None') {
                                                        Add-Member @MemberProps -Name 'Authentication Method' -Value $iScsiAuthenticationMethod
                                                    } elseif ($iScsiAuthenticationMethod -eq 'Use bidirectional CHAP') {
                                                        Add-Member @MemberProps -Name 'Authentication Method' -Value $iScsiAuthenticationMethod
                                                        Add-Member @MemberProps -Name 'Outgoing CHAP Name' -Value $VMHostHba.ExtensionData.AuthenticationProperties.ChapName
                                                        Add-Member @MemberProps -Name 'Incoming CHAP Name' -Value $VMHostHba.ExtensionData.AuthenticationProperties.MutualChapName
                                                    } else {
                                                        Add-Member @MemberProps -Name 'Authentication Method' -Value $iScsiAuthenticationMethod
                                                        Add-Member @MemberProps -Name 'Outgoing CHAP Name' -Value $VMHostHba.ExtensionData.AuthenticationProperties.ChapName
                                                    }
                                                    if ($InfoLevel.VMHost -eq 4) {
                                                        Add-Member @MemberProps -Name 'Advanced Options' -Value (($VMHostHba.ExtensionData.AdvancedOptions | ForEach-Object { "$($_.Key) = $($_.Value)" }) -join [Environment]::NewLine)
                                                    }
                                                }
                                                if ($VMHostStorageAdapter.Type -eq 'Fibre Channel') {
                                                    Add-Member @MemberProps -Name 'Node WWN' -Value (([String]::Format("{0:X}", $VMHostHba.NodeWorldWideName) -split "(\w{2})" | Where-Object { $_ -ne "" }) -join ":")
                                                    Add-Member @MemberProps -Name 'Port WWN' -Value (([String]::Format("{0:X}", $VMHostHba.PortWorldWideName) -split "(\w{2})" | Where-Object { $_ -ne "" }) -join ":")
                                                    Add-Member @MemberProps -Name 'Speed' -Value $VMHostHba.Speed
                                                }
                                                if ($Healthcheck.VMHost.StorageAdapter) {
                                                    $VMHostStorageAdapter | Where-Object { $_.'Status' -ne 'Online' } | Set-Style -Style Warning -Property 'Status'
                                                    $VMHostStorageAdapter | Where-Object { $_.'Status' -eq 'Offline' } | Set-Style -Style Critical -Property 'Status'
                                                }
                                                $VMHostStorageAdapter | Table -List -Name "$($VMHost.ExtensionData.Name) storage adapter $($VMHostStorageAdapter.Adapter)" -ColumnWidths 25, 75
                                            }
                                        }
                                    }
                                    #endregion ESXi Host Storage Adapters Section
                                }
                                #endregion ESXi Host Storage Adapter Information
                            }
                            #endregion ESXi Host Storage Section

                            #region ESXi Host Network Section
                            Section -Style Heading2 'Network' {
                                Paragraph "The following section details the host network configuration for $($VMHost.ExtensionData.Name)."
                                BlankLine
                                #region ESXi Host Network Configuration
                                $VMHostNetwork = $VMHost.ExtensionData.Config.Network
                                $VMHostVirtualSwitch = @()
                                $VMHostVss = foreach ($vSwitch in $VMHost.ExtensionData.Config.Network.Vswitch) {
                                    $VMHostVirtualSwitch += $vSwitch.Name
                                }
                                $VMHostDvs = foreach ($dvSwitch in $VMHost.ExtensionData.Config.Network.ProxySwitch) {
                                    $VMHostVirtualSwitch += $dvSwitch.DvsName
                                }
                                $VMHostNetworkDetail = [PSCustomObject]@{
                                    'Host' = $($VMHost.ExtensionData.Name)
                                    'Virtual Switches' = ($VMHostVirtualSwitch | Sort-Object) -join ', '
                                    'VMkernel Adapters' = ($VMHostNetwork.Vnic.Device | Sort-Object) -join ', '
                                    'Physical Adapters' = ($VMHostNetwork.Pnic.Device | Sort-Object) -join ', '
                                    'VMkernel Gateway' = $VMHostNetwork.IpRouteConfig.DefaultGateway
                                    'IPv6' = Switch ($VMHostNetwork.IPv6Enabled) {
                                        $true { 'Enabled' }
                                        $false { 'Disabled' }
                                    }
                                    'VMkernel IPv6 Gateway' = Switch ($VMHostNetwork.IpRouteConfig.IpV6DefaultGateway) {
                                        $null { '--' }
                                        default { $VMHostNetwork.IpRouteConfig.IpV6DefaultGateway }
                                    }
                                    'DNS Servers' = ($VMHostNetwork.DnsConfig.Address | Sort-Object) -join ', ' 
                                    'Host Name' = $VMHostNetwork.DnsConfig.HostName
                                    'Domain Name' = $VMHostNetwork.DnsConfig.DomainName 
                                    'Search Domain' = ($VMHostNetwork.DnsConfig.SearchDomain | Sort-Object) -join ', '
                                }
                                if ($Healthcheck.VMHost.IPv6) {
                                    $VMHostNetworkDetail | Where-Object { $_.'IPv6' -eq $false } | Set-Style -Style Warning -Property 'IPv6'
                                }
                                $VMHostNetworkDetail | Table -Name "$($VMHost.ExtensionData.Name) Network Configuration" -List -ColumnWidths 50, 50
                                #endregion ESXi Host Network Configuration

                                #region ESXi Host Physical Adapters
                                Section -Style Heading3 'Physical Adapters' {
                                    $PhysicalNetAdapters = $VMHost.ExtensionData.Config.Network.Pnic | Sort-Object Device
                                    $VMHostPhysicalNetAdapters = foreach ($PhysicalNetAdapter in $PhysicalNetAdapters) {
                                        [PSCustomObject]@{
                                            'Adapter' = $PhysicalNetAdapter.Device
                                            'Status' = Switch ($PhysicalNetAdapter.Linkspeed) {
                                                $null { 'Disconnected' }
                                                default { 'Connected' }
                                            }
                                            'Virtual Switch' = $(
                                                if ($VMHost.ExtensionData.Config.Network.Vswitch.Pnic -contains $PhysicalNetAdapter.Key) {
                                                    ($VMHost.ExtensionData.Config.Network.Vswitch | Where-Object { $_.Pnic -eq $PhysicalNetAdapter.Key }).Name
                                                } elseif ($VMHost.ExtensionData.Config.Network.ProxySwitch.Pnic -contains $PhysicalNetAdapter.Key) {
                                                    ($VMHost.ExtensionData.Config.Network.ProxySwitch | Where-Object { $_.Pnic -eq $PhysicalNetAdapter.Key }).DvsName
                                                } else {
                                                    '--'
                                                }
                                            )
                                            'MAC Address' = $PhysicalNetAdapter.Mac
                                            'Actual Speed, Duplex' = Switch ($PhysicalNetAdapter.LinkSpeed.SpeedMb) {
                                                $null { 'Down' }
                                                default {
                                                    if ($PhysicalNetAdapter.LinkSpeed.Duplex) {
                                                        "$($PhysicalNetAdapter.LinkSpeed.SpeedMb) Mbps, Full Duplex"
                                                    } else {
                                                        'Auto negotiate'
                                                    }
                                                }
                                            }
                                            'Configured Speed, Duplex' = Switch ($PhysicalNetAdapter.Spec.LinkSpeed) {
                                                $null { 'Auto negotiate' }
                                                default {
                                                    if ($PhysicalNetAdapter.Spec.LinkSpeed.Duplex) {
                                                        "$($PhysicalNetAdapter.Spec.LinkSpeed.SpeedMb) Mbps, Full Duplex"
                                                    } else {
                                                        "$($PhysicalNetAdapter.Spec.LinkSpeed.SpeedMb) Mbps"
                                                    }
                                                }
                                            }
                                            'Wake on LAN' = Switch ($PhysicalNetAdapter.WakeOnLanSupported) {
                                                $true { 'Supported' }
                                                $false { 'Not Supported' }
                                            }
                                        }
                                    }
                                    if ($Healthcheck.VMHost.NetworkAdapter) {
                                        $VMHostPhysicalNetAdapters | Where-Object { $_.'Status' -ne 'Connected' } | Set-Style -Style Critical -Property 'Status'
                                        $VMHostPhysicalNetAdapters | Where-Object { $_.'Actual Speed, Duplex' -eq 'Down' } | Set-Style -Style Critical -Property 'Actual Speed, Duplex'
                                    }
                                    if ($InfoLevel.VMHost -ge 4) {
                                        foreach ($VMHostPhysicalNetAdapter in $VMHostPhysicalNetAdapters) {
                                            Section -Style Heading4 "$($VMHostPhysicalNetAdapter.Adapter)" {
                                                $VMHostPhysicalNetAdapter | Table -List -Name "$($VMHost.ExtensionData.Name) Physical Adapter $($VMHostPhysicalNetAdapter.Adapter)" -ColumnWidths 50, 50
                                            }
                                        }
                                    } else {
                                        $VMHostPhysicalNetAdapters | Table -Name "$($VMHost.ExtensionData.Name) Physical Adapters"
                                    }
                                }
                                #endregion ESXi Host Physical Adapters
                    
                                #region ESXi Host Cisco Discovery Protocol
                                $VMHostNetworkAdapterCDP = $VMHost | Get-VMHostNetworkAdapterCDP | Where-Object { $_.Status -eq 'Connected' } | Sort-Object Device
                                if ($VMHostNetworkAdapterCDP) {
                                    Section -Style Heading3 'Cisco Discovery Protocol' {
                                        if ($InfoLevel.VMHost -ge 4) {
                                            foreach ($VMHostNetworkAdapter in $VMHostNetworkAdapterCDP) {
                                                Section -Style Heading4 "$($VMHostNetworkAdapter.Device)" {
                                                    $VMHostCDP = [PSCustomObject]@{
                                                        'Status' = $VMHostNetworkAdapter.Status
                                                        'System Name' = $VMHostNetworkAdapter.SystemName
                                                        'Hardware Platform' = $VMHostNetworkAdapter.HardwarePlatform
                                                        'Switch ID' = $VMHostNetworkAdapter.SwitchId
                                                        'Software Version' = $VMHostNetworkAdapter.SoftwareVersion
                                                        'Management Address' = $VMHostNetworkAdapter.ManagementAddress
                                                        'Address' = $VMHostNetworkAdapter.Address
                                                        'Port ID' = $VMHostNetworkAdapter.PortId
                                                        'VLAN' = $VMHostNetworkAdapter.Vlan
                                                        'MTU' = $VMHostNetworkAdapter.Mtu
                                                    }
                                                    $VMHostCDP | Table -List -Name "$($VMHost.ExtensionData.Name) Network Adapter $($VMHostNetworkAdapter.Device) CDP Information" -ColumnWidths 50, 50
                                                }
                                            }
                                        } else {
                                            $VMHostCDP = foreach ($VMHostNetworkAdapter in $VMHostNetworkAdapterCDP) {
                                                [PSCustomObject]@{
                                                    'Adapter' = $VMHostNetworkAdapter.Device
                                                    'Status' = $VMHostNetworkAdapter.Status
                                                    'Hardware Platform' = $VMHostNetworkAdapter.HardwarePlatform
                                                    'Switch ID' = $VMHostNetworkAdapter.SwitchId
                                                    'Address' = $VMHostNetworkAdapter.Address
                                                    'Port ID' = $VMHostNetworkAdapter.PortId
                                                }
                                            }
                                            $VMHostCDP | Table -Name "$($VMHost.ExtensionData.Name) Network Adapter CDP Information"
                                        }
                                    }
                                }
                                #endregion ESXi Host Cisco Discovery Protocol

                                #region ESXi Host VMkernel Adapaters
                                Section -Style Heading3 'VMkernel Adapters' {
                                    $VMkernelAdapters = $VMHost | Get-View | ForEach-Object -Process {
                                        $esx = $_
                                        $netSys = Get-View -Id $_.ConfigManager.NetworkSystem
                                        $vnicMgr = Get-View -Id $_.ConfigManager.VirtualNicManager
                                        $netSys.NetworkInfo.Vnic |
                                        ForEach-Object -Process {
                                            $device = $_.Device
                                            [PSCustomObject]@{
                                                'Adapter' = $_.Device
                                                'Port Group' = & {
                                                    if ($_.Spec.Portgroup) {
                                                        $script:pg = $_.Spec.Portgroup
                                                    } else {
                                                        $script:pg = Get-View -ViewType DistributedVirtualPortgroup -Property Name, Key -Filter @{'Key' = "$($_.Spec.DistributedVirtualPort.PortgroupKey)" } |
                                                        Select-Object -ExpandProperty Name
                                                    }
                                                    $script:pg
                                                }
                                                'Virtual Switch' = & { 
                                                    if ($_.Spec.Portgroup) {
                                                        (Get-VirtualPortGroup -Standard -Name $script:pg -VMHost $VMHost).VirtualSwitchName
                                                    } else {
                                                        (Get-VDPortgroup -Name $script:pg).VDSwitch.Name
                                                    }
                                                }
                                                'TCP/IP Stack' = Switch ($_.Spec.NetstackInstanceKey) {
                                                    'defaultTcpipStack' { 'Default' }
                                                    'vSphereProvisioning' { 'Provisioning' }
                                                    'vmotion' { 'vMotion' }
                                                    $null { 'Not Applicable' }
                                                    default { $_.Spec.NetstackInstanceKey }
                                                }
                                                'MTU' = $_.Spec.Mtu
                                                'MAC Address' = $_.Spec.Mac
                                                'DHCP' = Switch ($_.Spec.Ip.Dhcp) {
                                                    $true { 'Enabled' }
                                                    $false { 'Disabled' }
                                                }
                                                'IP Address' = $_.Spec.IP.IPAddress
                                                'Subnet Mask' = $_.Spec.IP.SubnetMask
                                                'Default Gateway' = Switch ($_.Spec.IpRouteSpec.IpRouteConfig.DefaultGateway) {
                                                    $null { '--' }
                                                    default { $_.Spec.IpRouteSpec.IpRouteConfig.DefaultGateway }
                                                }
                                                'vMotion' = Switch ((($vnicMgr.Info.NetConfig | where { $_.NicType -eq 'vmotion' }).SelectedVnic | % { $_ -match $device } ) -contains $true) {
                                                    $true { 'Enabled' }
                                                    $false { 'Disabled' }
                                                }
                                                'Provisioning' = Switch ((($vnicMgr.Info.NetConfig | where { $_.NicType -eq 'vSphereProvisioning' }).SelectedVnic | % { $_ -match $device } ) -contains $true) {
                                                    $true { 'Enabled' }
                                                    $false { 'Disabled' }
                                                }
                                                'FT Logging' = Switch ((($vnicMgr.Info.NetConfig | where { $_.NicType -eq 'faultToleranceLogging' }).SelectedVnic | % { $_ -match $device } ) -contains $true) {
                                                    $true { 'Enabled' }
                                                    $false { 'Disabled' }
                                                }
                                                'Management' = Switch ((($vnicMgr.Info.NetConfig | where { $_.NicType -eq 'management' }).SelectedVnic | % { $_ -match $device } ) -contains $true) {
                                                    $true { 'Enabled' }
                                                    $false { 'Disabled' }
                                                }
                                                'vSphere Replication' = Switch ((($vnicMgr.Info.NetConfig | where { $_.NicType -eq 'vSphereReplication' }).SelectedVnic | % { $_ -match $device } ) -contains $true) {
                                                    $true { 'Enabled' }
                                                    $false { 'Disabled' }
                                                }
                                                'vSphere Replication NFC' = Switch ((($vnicMgr.Info.NetConfig | where { $_.NicType -eq 'vSphereReplicationNFC' }).SelectedVnic | % { $_ -match $device } ) -contains $true) {
                                                    $true { 'Enabled' }
                                                    $false { 'Disabled' }
                                                }
                                                'vSAN' = Switch ((($vnicMgr.Info.NetConfig | where { $_.NicType -eq 'vsan' }).SelectedVnic | % { $_ -match $device } ) -contains $true) {
                                                    $true { 'Enabled' }
                                                    $false { 'Disabled' }
                                                }
                                                'vSAN Witness' = Switch ((($vnicMgr.Info.NetConfig | where { $_.NicType -eq 'vsanWitness' }).SelectedVnic | % { $_ -match $device } ) -contains $true) {
                                                    $true { 'Enabled' }
                                                    $false { 'Disabled' }
                                                }
                                            }
                                        }
                                    }
                                    foreach ($VMkernelAdapter in ($VMkernelAdapters | Sort-Object 'Adapter')) {
                                        Section -Style Heading4 "$($VMkernelAdapter.Adapter)" {
                                            $VMkernelAdapter | Table -List -Name "$($VMHost.ExtensionData.Name) VMkernel Adapter $($VMkernelAdapter.Adapter)" -ColumnWidths 50, 50
                                        }
                                    }
                                }
                                #endregion ESXi Host VMkernel Adapaters

                                #region ESXi Host Standard Virtual Switches
                                $VSSwitches = $VMHost | Get-VirtualSwitch -Standard | Sort-Object Name
                                if ($VSSwitches) {
                                    #region Section Standard Virtual Switches
                                    Section -Style Heading5 'Standard Virtual Switches' {
                                        Paragraph "The following section details the standard virtual switch configuration for $VMHost."
                                        BlankLine
                                        $VSSwitchNicTeaming = $VSSwitches | Get-NicTeamingPolicy
                                        #region ESXi Host Standard Virtual Switch Properties
                                        $VSSProperties = foreach ($VSSwitchNicTeam in $VSSwitchNicTeaming) {
                                            [PSCustomObject]@{
                                                'Virtual Switch' = $VSSwitchNicTeam.VirtualSwitch 
                                                'MTU' = $VSSwitchNicTeam.VirtualSwitch.Mtu 
                                                'Number of Ports' = $VSSwitchNicTeam.VirtualSwitch.NumPorts
                                                'Number of Ports Available' = $VSSwitchNicTeam.VirtualSwitch.NumPortsAvailable
                                            }
                                        }
                                        $VSSProperties | Table -Name "$VMHost Standard Virtual Switches"
                                        #endregion ESXi Host Standard Virtual Switch Properties
                                
                                        #region ESXi Host Virtual Switch Security Policy
                                        $VssSecurity = $VSSwitches | Get-SecurityPolicy
                                        if ($VssSecurity) {
                                            #region Virtual Switch Security Policy
                                            Section -Style Heading5 'Virtual Switch Security' {
                                                $VssSecurity = foreach ($VssSec in $VssSecurity) {
                                                    [PSCustomObject]@{
                                                        'Virtual Switch' = $VssSec.VirtualSwitch 
                                                        'Promiscuous Mode' = Switch ($VssSec.AllowPromiscuous) {
                                                            $true { 'Accept' }
                                                            $false { 'Reject' }
                                                        }
                                                        'MAC Address Changes' = Switch ($VssSec.MacChanges) {
                                                            $true { 'Accept' }
                                                            $false { 'Reject' }
                                                        } 
                                                        'Forged Transmits' = Switch ($VssSec.ForgedTransmits) {
                                                            $true { 'Accept' }
                                                            $false { 'Reject' }
                                                        } 
                                                    }
                                                }
                                                $VssSecurity | Sort-Object 'Virtual Switch' | Table -Name "$VMHost Virtual Switch Security Policy"
                                            }
                                            #endregion Virtual Switch Security Policy
                                        }
                                        #endregion ESXi Host Virtual Switch Security Policy

                                        #region ESXi Host Virtual Switch Traffic Shaping Policy
                                        Section -Style Heading5 'Virtual Switch Traffic Shaping' {
                                            $VssTrafficShapingPolicy = foreach ($VSSwitch in $VSSwitches) {
                                                [PSCustomObject]@{
                                                    'Virtual Switch' = $VSSwitch.Name
                                                    'Status' = Switch ($VSSwitch.ExtensionData.Spec.Policy.ShapingPolicy.Enabled) {
                                                        $True { 'Enabled' }
                                                        $False { 'Disabled' }
                                                    }
                                                    'Average Bandwidth (kbit/s)' = $VSSwitch.ExtensionData.Spec.Policy.ShapingPolicy.AverageBandwidth
                                                    'Peak Bandwidth (kbit/s)' = $VSSwitch.ExtensionData.Spec.Policy.ShapingPolicy.PeakBandwidth
                                                    'Burst Size (KB)' = $VSSwitch.ExtensionData.Spec.Policy.ShapingPolicy.BurstSize
                                                }
                                            }
                                            $VssTrafficShapingPolicy | Sort-Object 'Virtual Switch' | Table -Name "$VMHost Virtual Switch Traffic Shaping Policy"
                                        }
                                        #endregion ESXi Host Virtual Switch Traffic Shaping Policy

                                        #region ESXi Host Virtual Switch Teaming & Failover
                                        $VssNicTeamingPolicy = $VSSwitches | Get-NicTeamingPolicy
                                        if ($VssNicTeamingPolicy) {
                                            #region Virtual Switch Teaming & Failover Section
                                            Section -Style Heading5 'Virtual Switch Teaming & Failover' {
                                                $VssNicTeaming = foreach ($VssNicTeam in $VssNicTeamingPolicy) {
                                                    [PSCustomObject]@{
                                                        'Virtual Switch' = $VssNicTeam.VirtualSwitch 
                                                        'Load Balancing' = Switch ($VssNicTeam.LoadBalancingPolicy) {
                                                            'LoadbalanceSrcId' { 'Route based on the originating port ID' }
                                                            'LoadbalanceSrcMac' { 'Route based on source MAC hash' }
                                                            'LoadbalanceIP' { 'Route based on IP hash' }
                                                            'ExplicitFailover' { 'Explicit Failover' }
                                                            default { $VssNicTeam.LoadBalancingPolicy }
                                                        }
                                                        'Network Failure Detection' = Switch ($VssNicTeam.NetworkFailoverDetectionPolicy) {
                                                            'LinkStatus' { 'Link status only' }
                                                            'BeaconProbing' { 'Beacon probing' }
                                                            default { $VssNicTeam.NetworkFailoverDetectionPolicy }
                                                        } 
                                                        'Notify Switches' = Switch ($VssNicTeam.NotifySwitches) {
                                                            $true { 'Yes' }
                                                            $false { 'No' }
                                                        }
                                                        'Failback' = Switch ($VssNicTeam.FailbackEnabled) {
                                                            $true { 'Yes' }
                                                            $false { 'No' }
                                                        }
                                                        'Active NICs' = ($VssNicTeam.ActiveNic | Sort-Object) -join [Environment]::NewLine
                                                        'Standby NICs' = ($VssNicTeam.StandbyNic | Sort-Object) -join [Environment]::NewLine
                                                        'Unused NICs' = ($VssNicTeam.UnusedNic | Sort-Object) -join [Environment]::NewLine
                                                    }
                                                }
                                                $VssNicTeaming | Sort-Object 'Virtual Switch' | Table -Name "$VMHost Virtual Switch Teaming & Failover"
                                            }
                                            #endregion Virtual Switch Teaming & Failover Section
                                        }
                                        #endregion ESXi Host Virtual Switch Teaming & Failover
                                
                                        #region ESXi Host Virtual Switch Port Groups
                                        $VssPortgroups = $VSSwitches | Get-VirtualPortGroup -Standard 
                                        if ($VssPortgroups) {
                                            Section -Style Heading5 'Virtual Switch Port Groups' {
                                                $VssPortgroups = foreach ($VssPortgroup in $VssPortgroups) {
                                                    [PSCustomObject]@{
                                                        'Port Group' = $VssPortgroup.Name
                                                        'VLAN ID' = $VssPortgroup.VLanId 
                                                        'Virtual Switch' = $VssPortgroup.VirtualSwitchName
                                                        '# of VMs' = ($VssPortgroup | Get-VM).Count
                                                    }
                                                }
                                                $VssPortgroups | Sort-Object 'Port Group', 'VLAN ID', 'Virtual Switch' | Table -Name "$VMHost Virtual Switch Port Group Information"
                                            }
                                            #endregion ESXi Host Virtual Switch Port Groups
                                
                                            #region ESXi Host Virtual Switch Port Group Security Policy
                                            $VssPortgroupSecurity = $VSSwitches | Get-VirtualPortGroup | Get-SecurityPolicy 
                                            if ($VssPortgroupSecurity) {
                                                #region Virtual Port Group Security Policy Section
                                                Section -Style Heading5 'Virtual Switch Port Group Security' {
                                                    $VssPortgroupSecurity = foreach ($VssPortgroupSec in $VssPortgroupSecurity) {
                                                        [PSCustomObject]@{
                                                            'Port Group' = $VssPortgroupSec.VirtualPortGroup
                                                            'Virtual Switch' = $VssPortgroupSec.virtualportgroup.virtualswitchname
                                                            'Promiscuous Mode' = Switch ($VssPortgroupSec.AllowPromiscuous) {
                                                                $true { 'Accept' }
                                                                $false { 'Reject' }
                                                            }
                                                            'MAC Changes' = Switch ($VssPortgroupSec.MacChanges) {
                                                                $true { 'Accept' }
                                                                $false { 'Reject' }
                                                            }
                                                            'Forged Transmits' = Switch ($VssPortgroupSec.ForgedTransmits) {
                                                                $true { 'Accept' }
                                                                $false { 'Reject' }
                                                            } 
                                                        }
                                                    }
                                                    $VssPortgroupSecurity | Sort-Object 'Port Group', 'Virtual Switch' | Table -Name "$VMHost Virtual Switch Port Group Security Policy" 
                                                }
                                                #endregion Virtual Port Group Security Policy Section
                                            }
                                            #endregion ESXi Host Virtual Switch Port Group Security Policy
                                                                                        
                                            #region ESXi Host Virtual Switch Port Group Traffic Shaping Policy
                                            Section -Style Heading5 'Virtual Switch Port Group Traffic Shaping' {    
                                                $VssPortgroupTrafficShapingPolicy = foreach ($VssPortgroup in $VssPortgroups) {
                                                    [PSCustomObject]@{
                                                        'Port Group' = $VssPortgroup.Name 
                                                        'Virtual Switch' = $VssPortgroup.VirtualSwitchName
                                                        'Status' = Switch ($VssPortgroup.ExtensionData.Spec.Policy.ShapingPolicy.Enabled) {
                                                            $True { 'Enabled' }
                                                            $False { 'Disabled' }
                                                            $null { 'Inherited' }
                                                        }
                                                        'Average Bandwidth (kbit/s)' = $VssPortgroup.ExtensionData.Spec.Policy.ShapingPolicy.AverageBandwidth
                                                        'Peak Bandwidth (kbit/s)' = $VssPortgroup.ExtensionData.Spec.Policy.ShapingPolicy.PeakBandwidth
                                                        'Burst Size (KB)' = $VssPortgroup.ExtensionData.Spec.Policy.ShapingPolicy.BurstSize
                                                    }
                                                }
                                                $VssPortgroupTrafficShapingPolicy | Sort-Object 'Port Group', 'Virtual Switch' | Table -Name "$VMHost Virtual Switch Port Group Traffic Shaping Policy"
                                            }
                                            #endregion ESXi Host Virtual Switch Port Group Traffic Shaping Policy
                                
                                            #region ESXi Host Virtual Switch Port Group Teaming & Failover
                                            $VssPortgroupNicTeaming = $VSSwitches | Get-VirtualPortGroup | Get-NicTeamingPolicy 
                                            if ($VssPortgroupNicTeaming) {
                                                #region Virtual Switch Port Group Teaming & Failover Section
                                                Section -Style Heading5 'Virtual Switch Port Group Teaming & Failover' {
                                                    $VssPortgroupNicTeaming = foreach ($VssPortgroupNicTeam in $VssPortgroupNicTeaming) {
                                                        [PSCustomObject]@{
                                                            'Port Group' = $VssPortgroupNicTeam.VirtualPortGroup
                                                            'Virtual Switch' = $VssPortgroupNicTeam.virtualportgroup.virtualswitchname 
                                                            'Load Balancing' = Switch ($VssPortgroupNicTeam.LoadBalancingPolicy) {
                                                                'LoadbalanceSrcId' { 'Route based on the originating port ID' }
                                                                'LoadbalanceSrcMac' { 'Route based on source MAC hash' }
                                                                'LoadbalanceIP' { 'Route based on IP hash' }
                                                                'ExplicitFailover' { 'Explicit Failover' }
                                                                default { $VssPortgroupNicTeam.LoadBalancingPolicy }
                                                            }
                                                            'Network Failure Detection' = Switch ($VssPortgroupNicTeam.NetworkFailoverDetectionPolicy) {
                                                                'LinkStatus' { 'Link status only' }
                                                                'BeaconProbing' { 'Beacon probing' }
                                                                default { $VssPortgroupNicTeam.NetworkFailoverDetectionPolicy }
                                                            }  
                                                            'Notify Switches' = Switch ($VssPortgroupNicTeam.NotifySwitches) {
                                                                $true { 'Yes' }
                                                                $false { 'No' }
                                                            }
                                                            'Failback' = Switch ($VssPortgroupNicTeam.FailbackEnabled) {
                                                                $true { 'Yes' }
                                                                $false { 'No' }
                                                            } 
                                                            'Active NICs' = ($VssPortgroupNicTeam.ActiveNic | Sort-Object) -join [Environment]::NewLine
                                                            'Standby NICs' = ($VssPortgroupNicTeam.StandbyNic | Sort-Object) -join [Environment]::NewLine
                                                            'Unused NICs' = ($VssPortgroupNicTeam.UnusedNic | Sort-Object) -join [Environment]::NewLine
                                                        }
                                                    }
                                                    $VssPortgroupNicTeaming | Sort-Object 'Port Group', 'Virtual Switch' | Table -Name "$VMHost Virtual Switch Port Group Teaming & Failover"
                                                }
                                                #endregion Virtual Switch Port Group Teaming & Failover Section
                                            }
                                            #endregion ESXi Host Virtual Switch Port Group Teaming & Failover
                                        }
                                    }
                                    #endregion Section Standard Virtual Switches
                                }
                                #endregion ESXi Host Standard Virtual Switches

                                #region Distributed Virtual Switch Section
                                # Create Distributed Switch Section if they exist
                                $VDSwitches = Get-VDSwitch -Server $ESXi
                                if ($VDSwitches) {
                                    Section -Style Heading3 'Distributed Virtual Switches' {
                                        #region Distributed Virtual Switch Informative Information
                                        if ($InfoLevel.Network -eq 2) {
                                            $VDSInfo = foreach ($VDS in $VDSwitches) {
                                                [PSCustomObject]@{
                                                    'Distributed Switch' = $VDS.Name
                                                    '# of Uplinks' = $VDS.NumUplinkPorts
                                                    '# of Ports' = $VDS.NumPorts 
                                                    '# of Hosts' = $VDS.ExtensionData.Summary.HostMember.Count
                                                    '# of VMs' = $VDS.ExtensionData.Summary.VM.Count
                                                }
                                            }    
                                            $VDSInfo | Table -Name 'Distributed Switch Information'
                                        }    
                                        #endregion Distributed Switch Informative Information

                                        #region Distributed Switch Detailed Information
                                        if ($InfoLevel.Network -ge 3) {
                                            ## TODO: LACP, NetFlow, NIOC
                                            foreach ($VDS in ($VDSwitches)) {
                                                #region VDS Section
                                                Section -Style Heading4 $VDS {
                                                    #region Distributed Switch General Properties
                                                    $VDSwitchDetail = [PSCustomObject]@{
                                                        'Distributed Switch' = $VDS.Name
                                                        'ID' = $VDS.Id
                                                        'Number of Ports' = $VDS.NumPorts
                                                        'Number of Port Groups' = $VDS.ExtensionData.Summary.PortGroupName.Count 
                                                        'Number of VMs' = $VDS.ExtensionData.Summary.VM.Count 
                                                        'MTU' = $VDS.Mtu
                                                        'Network I/O Control' = Switch ($VDS.ExtensionData.Config.NetworkResourceManagementEnabled) {
                                                            $true { 'Enabled' }
                                                            $false { 'Disabled' }
                                                        } 
                                                        'Discovery Protocol' = $VDS.LinkDiscoveryProtocol
                                                        'Discovery Protocol Operation' = $VDS.LinkDiscoveryProtocolOperation
                                                    }

                                                    #region Network Advanced Detail Information
                                                    if ($InfoLevel.Network -ge 4) {
                                                        $VDSwitchDetail | ForEach-Object {
                                                            $VDSwitchVMs = $VDS | Get-VM | Sort-Object 
                                                            Add-Member -InputObject $_ -MemberType NoteProperty -Name 'Virtual Machines' -Value ($VDSwitchVMs.Name -join ', ')
                                                        }
                                                    }
                                                    #endregion Network Advanced Detail Information
                                                    $VDSwitchDetail | Table -Name "$VDS Distributed Switch General Properties" -List -ColumnWidths 50, 50 
                                                    #endregion Distributed Switch General Properties

                                                    #region Distributed Switch Uplink Ports
                                                    $VdsUplinks = $VDS | Get-VDPortgroup | Where-Object { $_.IsUplink -eq $true } | Get-VDPort
                                                    if ($VdsUplinks) {
                                                        Section -Style Heading4 'Distributed Switch Uplink Ports' {
                                                            $VdsUplinkDetail = foreach ($VdsUplink in $VdsUplinks) {
                                                                [PSCustomObject]@{
                                                                    'Distributed Switch' = $VdsUplink.Switch
                                                                    'Uplink Name' = $VdsUplink.Name
                                                                    'Physical Network Adapter' = $VdsUplink.ConnectedEntity
                                                                    'Uplink Port Group' = $VdsUplink.Portgroup
                                                                }
                                                            }
                                                            $VdsUplinkDetail | Sort-Object 'Distributed Switch', 'Uplink Name' | Table -Name "$VDS Distributed Switch Uplink Ports"
                                                        }
                                                    }
                                                    #endregion Distributed Virtual Switch Uplink Ports
                                                    
                                                    #region Distributed Switch Port Groups
                                                    $VDSPortgroups = $VDS | Get-VDPortgroup
                                                    if ($VDSPortgroups) {
                                                        Section -Style Heading4 'Distributed Switch Port Groups' {
                                                            $VDSPortgroupDetail = foreach ($VDSPortgroup in $VDSPortgroups) {
                                                                [PSCustomObject]@{
                                                                    'Port Group' = $VDSPortgroup.Name
                                                                    'Distributed Switch' = $VDSPortgroup.VDSwitch.Name
                                                                    'VLAN Configuration' = Switch ($VDSPortgroup.VlanConfiguration) {
                                                                        $null { '--' }
                                                                        default { $VDSPortgroup.VlanConfiguration }
                                                                    }
                                                                    'Port Binding' = $VDSPortgroup.PortBinding
                                                                }
                                                            }
                                                            $VDSPortgroupDetail | Sort-Object 'Port Group' | Table -Name "$VDS Distributed Switch Port Groups" 
                                                        }
                                                    }
                                                    #endregion Distributed Switch Port Groups

                                                    #region Distributed Switch Private VLANs
                                                    $VDSwitchPrivateVLANs = $VDS | Get-VDSwitchPrivateVlan
                                                    if ($VDSwitchPrivateVLANs) {
                                                        Section -Style Heading4 'Distributed Switch Private VLANs' {
                                                            $VDSPvlan = foreach ($VDSwitchPrivateVLAN in $VDSwitchPrivateVLANs) {
                                                                [PSCustomObject]@{
                                                                    'Primary VLAN ID' = $VDSwitchPrivateVLAN.PrimaryVlanId
                                                                    'Private VLAN Type' = $VDSwitchPrivateVLAN.PrivateVlanType
                                                                    'Secondary VLAN ID' = $VDSwitchPrivateVLAN.SecondaryVlanId
                                                                }
                                                            }
                                                            $VDSPvlan | Sort-Object 'Primary VLAN ID', 'Secondary VLAN ID' | Table -Name "$VDS Distributed Switch Private VLANs"
                                                        }
                                                    }
                                                    #endregion Distributed Switch Private VLANs
                                                }
                                                #endregion VDS Section
                                            }
                                        }
                                        #endregion Distributed Virtual Switch Detailed Information
                                    }
                                }
                                #endregion Distributed Virtual Switch Section
                            }                
                            #endregion ESXi Host Network Section

                            #region ESXi Host Security Section
                            Section -Style Heading2 'Security' {
                                Paragraph "The following section details the host security configuration for $($VMHost.ExtensionData.Name)."
                                #region ESXi Host Lockdown Mode
                                if ($VMHost.ExtensionData.Config.LockdownMode -ne $null) {
                                    Section -Style Heading3 'Lockdown Mode' {
                                        $LockdownMode = [PSCustomObject]@{
                                            'Lockdown Mode' = Switch ($VMHost.ExtensionData.Config.LockdownMode) {
                                                'lockdownDisabled' { 'Disabled' }
                                                'lockdownNormal' { 'Enabled (Normal)' }
                                                'lockdownStrict' { 'Enabled (Strict)' }
                                                default { $VMHost.ExtensionData.Config.LockdownMode }
                                            }
                                        }
                                        if ($Healthcheck.VMHost.LockdownMode) {
                                            $LockdownMode | Where-Object { $_.'Lockdown Mode' -eq 'Disabled' } | Set-Style -Style Warning -Property 'Lockdown Mode'
                                        }
                                        $LockdownMode | Table -Name "$($VMHost.ExtensionData.Name) Lockdown Mode" -List -ColumnWidths 50, 50
                                    }
                                }
                                #endregion ESXi Host Lockdown Mode

                                #region ESXi Host Services
                                Section -Style Heading3 'Services' {
                                    $VMHostServices = $VMHost | Get-VMHostService
                                    $Services = foreach ($VMHostService in $VMHostServices) {
                                        [PSCustomObject]@{
                                            'Service' = $VMHostService.Label
                                            'Daemon' = Switch ($VMHostService.Running) {
                                                $true { 'Running' }
                                                $false { 'Stopped' }
                                            }
                                            'Startup Policy' = Switch ($VMHostService.Policy) {
                                                'automatic' { 'Start and stop with port usage' }
                                                'on' { 'Start and stop with host' }
                                                'off' { 'Start and stop manually' }
                                                default { $VMHostService.Policy }
                                            }
                                        }
                                    }
                                    if ($Healthcheck.VMHost.NTP) {
                                        $Services | Where-Object { ($_.'Service' -eq 'NTP Daemon') -and ($_.Daemon -eq 'Stopped') } | Set-Style -Style Critical -Property 'Daemon'
                                        $Services | Where-Object { ($_.'Service' -eq 'NTP Daemon') -and ($_.'Startup Policy' -ne 'Start and stop with host') } | Set-Style -Style Critical -Property 'Startup Policy'
                                    }
                                    if ($Healthcheck.VMHost.SSH) {
                                        $Services | Where-Object { ($_.'Service' -eq 'SSH') -and ($_.Daemon -eq 'Running') } | Set-Style -Style Warning -Property 'Daemon'
                                        $Services | Where-Object { ($_.'Service' -eq 'SSH') -and ($_.'Startup Policy' -ne 'Start and stop manually') } | Set-Style -Style Warning -Property 'Startup Policy'
                                    }
                                    if ($Healthcheck.VMHost.ESXiShell) {
                                        $Services | Where-Object { ($_.'Service' -eq 'ESXi Shell') -and ($_.Daemon -eq 'Running') } | Set-Style -Style Warning -Property 'Daemon'
                                        $Services | Where-Object { ($_.'Service' -eq 'ESXi Shell') -and ($_.'Startup Policy' -ne 'Start and stop manually') } | Set-Style -Style Warning -Property 'Startup Policy'
                                    }
                                    $Services | Sort-Object 'Service' | Table -Name "$($VMHost.ExtensionData.Name) Services" 
                                }
                                #endregion ESXi Host Services

                                #region ESXi Host Advanced Detail Information
                                if ($InfoLevel.VMHost -ge 4) {
                                    #region ESXi Host Firewall
                                    $VMHostFirewallExceptions = $VMHost | Get-VMHostFirewallException
                                    if ($VMHostFirewallExceptions) {
                                        #region Friewall Section
                                        Section -Style Heading3 'Firewall' {
                                            $VMHostFirewall = foreach ($VMHostFirewallException in $VMHostFirewallExceptions) {
                                                [PScustomObject]@{
                                                    'Service' = $VMHostFirewallException.Name
                                                    'Status' = Switch ($VMHostFirewallException.Enabled) {
                                                        $true { 'Enabled' }
                                                        $false { 'Disabled' }
                                                    }
                                                    'Incoming Ports' = $VMHostFirewallException.IncomingPorts
                                                    'Outgoing Ports' = $VMHostFirewallException.OutgoingPorts
                                                    'Protocols' = $VMHostFirewallException.Protocols
                                                    'Daemon' = Switch ($VMHostFirewallException.ServiceRunning) {
                                                        $true { 'Running' }
                                                        $false { 'Stopped' }
                                                        $null { 'N/A' }
                                                        default { $VMHostFirewallException.ServiceRunning }
                                                    }
                                                }
                                            }
                                            $VMHostFirewall | Sort-Object 'Service' | Table -Name "$($VMHost.ExtensionData.Name) Firewall Configuration" 
                                        }
                                        #endregion Friewall Section
                                    }
                                    #endregion ESXi Host Firewall
    
                                    #region ESXi Host Authentication
                                    $AuthServices = $VMHost | Get-VMHostAuthentication
                                    if ($AuthServices.DomainMembershipStatus) {
                                        Section -Style Heading3 'Authentication Services' {
                                            $AuthServices = $AuthServices | Select-Object Domain, @{L = 'Domain Membership'; E = { $_.DomainMembershipStatus } }, @{L = 'Trusted Domains'; E = { $_.TrustedDomains } }
                                            $AuthServices | Table -Name "$($VMHost.ExtensionData.Name) Authentication Services" -ColumnWidths 25, 25, 50 
                                        }    
                                    }
                                    #endregion ESXi Host Authentication
                                }
                                #endregion ESXi Host Advanced Detail Information
                            }
                            #endregion ESXi Host Security Section

                            #region Virtual Machine Section
                            if ($InfoLevel.VM -ge 1) {
                                if ($VMs) {
                                    Section -Style Heading2 'Virtual Machines' {
                                        Paragraph "The following section details the configuration of virtual machines managed by $($VMHost.ExtensionData.Name)."
                                        #region Virtual Machine Summary Information
                                        if ($InfoLevel.VM -eq 1) {
                                            BlankLine
                                            $VMSummary = [PSCustomObject]@{
                                                'Total VMs' = $VMs.Count
                                                'Total vCPUs' = ($VMs | Measure-Object -Property NumCpu -Sum).Sum
                                                'Total Memory' = "$([math]::Round(($VMs | Measure-Object -Property MemoryGB -Sum).Sum, 2)) GB"
                                                'Total Provisioned Space' = "$([math]::Round(($VMs | Measure-Object -Property ProvisionedSpaceGB -Sum).Sum, 2)) GB"
                                                'Total Used Space' = "$([math]::Round(($VMs | Measure-Object -Property UsedSpaceGB -Sum).Sum, 2)) GB"
                                                'VMs Powered On' = ($VMs | Where-Object { $_.PowerState -eq 'PoweredOn' }).Count
                                                'VMs Powered Off' = ($VMs | Where-Object { $_.PowerState -eq 'PoweredOff' }).Count
                                                'VMs Suspended' = ($VMs | Where-Object { $_.PowerState -eq 'Suspended' }).Count
                                                'VMs with Snapshots' = ($VMs | Where-Object { $_.ExtensionData.Snapshot }).Count
                                                'Guest Operating System Types' = (($VMs | Get-View).Summary.Config.GuestFullName | Select-Object -Unique).Count
                                                'VM Tools OK' = ($VMs | Where-Object { $_.ExtensionData.Guest.ToolsStatus -eq 'toolsOK' }).Count
                                                'VM Tools Old' = ($VMs | Where-Object { $_.ExtensionData.Guest.ToolsStatus -eq 'toolsOld' }).Count
                                                'VM Tools Not Running' = ($VMs | Where-Object { $_.ExtensionData.Guest.ToolsStatus -eq 'toolsNotRunning' }).Count
                                                'VM Tools Not Installed' = ($VMs | Where-Object { $_.ExtensionData.Guest.ToolsStatus -eq 'toolsNotInstalled' }).Count
                                            }
                                            $VMSummary | Table -List -Name 'VM Summary' -ColumnWidths 50, 50
                                        }
                                        #endregion Virtual Machine Summary Information

                                        #region Virtual Machine Informative Information
                                        if ($InfoLevel.VM -eq 2) {
                                            BlankLine
                                            $VMSnapshotList = $VMs.Extensiondata.Snapshot.RootSnapshotList
                                            $VMInfo = foreach ($VM in $VMs) {
                                                $VMView = $VM | Get-View
                                                [PSCustomObject]@{
                                                    'Virtual Machine' = $VM.Name
                                                    'Power State' = Switch ($VM.PowerState) {
                                                        'PoweredOn' { 'On' }
                                                        'PoweredOff' { 'Off' }
                                                        default { $VM.PowerState }
                                                    }
                                                    'IP Address' = Switch ($VMView.Guest.IpAddress) {
                                                        $null { '--' }
                                                        default { $VMView.Guest.IpAddress }
                                                    }
                                                    'vCPUs' = $VM.NumCpu
                                                    'Memory GB' = [math]::Round(($VM.MemoryGB), 0)
                                                    'Provisioned GB' = [math]::Round(($VM.ProvisionedSpaceGB), 0)
                                                    'Used GB' = [math]::Round(($VM.UsedSpaceGB), 0)
                                                    'HW Version' = ($VM.HardwareVersion).Replace('vmx-', 'v')
                                                    'VM Tools Status' = Switch ($VMView.Guest.ToolsStatus) {
                                                        'toolsOld' { 'Old' }
                                                        'toolsOK' { 'OK' }
                                                        'toolsNotRunning' { 'Not Running' }
                                                        'toolsNotInstalled' { 'Not Installed' }
                                                        default { $VMView.Guest.ToolsStatus }
                                                    }         
                                                }
                                            }
                                            if ($Healthcheck.VM.VMToolsStatus) {
                                                $VMInfo | Where-Object { $_.'VM Tools Status' -ne 'OK' } | Set-Style -Style Warning -Property 'VM Tools Status'
                                            }
                                            if ($Healthcheck.VM.PowerState) {
                                                $VMInfo | Where-Object { $_.'Power State' -ne 'On' } | Set-Style -Style Warning -Property 'Power State'
                                            }
                                            $VMInfo | Table -Name 'VM Informative Information'

                                            #region VM Snapshot Information
                                            if ($VMSnapshotList -and $Options.ShowVMSnapshots) {
                                                Section -Style Heading3 'Snapshots' {
                                                    $VMSnapshotInfo = foreach ($VMSnapshot in $VMSnapshotList) {
                                                        [PSCustomObject]@{
                                                            'Virtual Machine' = $VMLookup."$($VMSnapshot.VM)"
                                                            'Snapshot Name' = $VMSnapshot.Name
                                                            'Description' = $VMSnapshot.Description
                                                            'Days Old' = ((Get-Date).ToUniversalTime() - $VMSnapshot.CreateTime).Days
                                                        } 
                                                    }
                                                    if ($Healthcheck.VM.VMSnapshots) {
                                                        $VMSnapshotInfo | Where-Object { $_.'Days Old' -ge 7 } | Set-Style -Style Warning 
                                                        $VMSnapshotInfo | Where-Object { $_.'Days Old' -ge 14 } | Set-Style -Style Critical
                                                    }
                                                    $VMSnapshotInfo | Table -Name 'VM Snapshot Information'
                                                }
                                            }
                                            #endregion VM Snapshot Information
                                        }
                                        #endregion Virtual Machine Informative Information

                                        #region Virtual Machine Detailed Information
                                        if ($InfoLevel.VM -ge 3) {
                                            foreach ($VM in $VMs) {
                                                Section -Style Heading3 $VM.name {
                                                    $VMUptime = @()
                                                    $VMUptime = Get-Uptime -VM $VM
                                                    $VMSpbmPolicy = $VMSpbmConfig | Where-Object { $_.entity -eq $vm }
                                                    $VMView = $VM | Get-View
                                                    $VMSnapshotList = $vmview.Snapshot.RootSnapshotList
                                                    $VMDetail = [PSCustomObject]@{
                                                        'Virtual Machine' = $VM.Name
                                                        'ID' = $VM.Id 
                                                        'Operating System' = $VMView.Summary.Config.GuestFullName
                                                        'Hardware Version' = ($VM.HardwareVersion).Replace('vmx-', 'v')
                                                        'Power State' = Switch ($VM.PowerState) {
                                                            'PoweredOn' { 'On' }
                                                            'PoweredOff' { 'Off' }
                                                            default { $VM.PowerState }
                                                        }
                                                        'Connection State' = $TextInfo.ToTitleCase($VM.ExtensionData.Runtime.ConnectionState)
                                                        'VM Tools Status' = Switch ($VMView.Guest.ToolsStatus) {
                                                            'toolsOld' { 'Old' }
                                                            'toolsOK' { 'OK' }
                                                            'toolsNotRunning' { 'Not Running' }
                                                            'toolsNotInstalled' { 'Not Installed' }
                                                            default { $VMView.Guest.ToolsStatus }
                                                        }
                                                        'Fault Tolerance State' = Switch ($VMView.Runtime.FaultToleranceState) {
                                                            'notConfigured' { 'Not Configured' }
                                                            'needsSecondary' { 'Needs Secondary' }
                                                            'running' { 'Running' }
                                                            'disabled' { 'Disabled' }
                                                            'starting' { 'Starting' }
                                                            'enabled' { 'Enabled' }
                                                            default { $VMview.Runtime.FaultToleranceState }
                                                        } 
                                                        'vCPUs' = $VM.NumCpu
                                                        'Cores per Socket' = $VM.CoresPerSocket
                                                        'CPU Shares' = "$($VM.VMResourceConfiguration.CpuSharesLevel) / $($VM.VMResourceConfiguration.NumCpuShares)"
                                                        'CPU Reservation' = $VM.VMResourceConfiguration.CpuReservationMhz
                                                        'CPU Limit' = "$($VM.VMResourceConfiguration.CpuReservationMhz) MHz" 
                                                        'CPU Hot Add' = Switch ($VMView.Config.CpuHotAddEnabled) {
                                                            $true { 'Enabled' }
                                                            $false { 'Disabled' }
                                                        }
                                                        'CPU Hot Remove' = Switch ($VMView.Config.CpuHotRemoveEnabled) {
                                                            $true { 'Enabled' }
                                                            $false { 'Disabled' }
                                                        } 
                                                        'Memory Allocation' = "$([math]::Round(($VM.memoryGB), 2)) GB" 
                                                        'Memory Shares' = "$($VM.VMResourceConfiguration.MemSharesLevel) / $($VM.VMResourceConfiguration.NumMemShares)"
                                                        'Memory Hot Add' = Switch ($VMView.Config.MemoryHotAddEnabled) {
                                                            $true { 'Enabled' }
                                                            $false { 'Disabled' }
                                                        }
                                                        'vNICs' = $VMView.Summary.Config.NumEthernetCards
                                                        'DNS Name' = if ($VMView.Guest.HostName) {
                                                            $VMView.Guest.HostName
                                                        } else {
                                                            '--'
                                                        }
                                                        'Networks' = if ($VMView.Guest.Net.Network) {
                                                            (($VMView.Guest.Net | Where-Object { $_.Network -ne $null } | Select-Object Network | Sort-Object Network).Network -join ', ')
                                                        } else {
                                                            '--'
                                                        }
                                                        'IP Address' = if ($VMView.Guest.Net.IpAddress) {
                                                            (($VMView.Guest.Net | Where-Object { ($_.Network -ne $null) -and ($_.IpAddress -ne $null) } | Select-Object IpAddress | Sort-Object IpAddress).IpAddress -join ', ')
                                                        } else {
                                                            '--'
                                                        }
                                                        'MAC Address' = if ($VMView.Guest.Net.MacAddress) {
                                                            (($VMView.Guest.Net | Where-Object { $_.Network -ne $null } | Select-Object -Property MacAddress).MacAddress -join ', ')
                                                        } else {
                                                            '--'
                                                        }
                                                        'vDisks' = $VMView.Summary.Config.NumVirtualDisks
                                                        'Provisioned Space' = "$([math]::Round(($VM.ProvisionedSpaceGB), 2)) GB"
                                                        'Used Space' = "$([math]::Round(($VM.UsedSpaceGB), 2)) GB"
                                                        'Changed Block Tracking' = Switch ($VMView.Config.ChangeTrackingEnabled) {
                                                            $true { 'Enabled' }
                                                            $false { 'Disabled' }
                                                        }
                                                    }
                                                    $MemberProps = @{
                                                        'InputObject' = $VMDetail
                                                        'MemberType' = 'NoteProperty'
                                                    }
                                                    #if ($VMView.Config.CreateDate) {
                                                    # Add-Member @MemberProps -Name 'Creation Date' -Value ($VMView.Config.CreateDate).ToLocalTime()
                                                    #}
                                                    if ($VM.Notes) {
                                                        Add-Member @MemberProps -Name 'Notes' -Value $VM.Notes  
                                                    }
                                                    if ($VMView.Runtime.BootTime) {
                                                        Add-Member @MemberProps -Name 'Boot Time' -Value ($VMView.Runtime.BootTime).ToLocalTime()
                                                    }
                                                    if ($VMUptime.UptimeDays) {
                                                        Add-Member @MemberProps -Name 'Uptime Days' -Value $VMUptime.UptimeDays
                                                    }

                                                    #region VM Health Checks
                                                    if ($Healthcheck.VM.VMToolsStatus) {
                                                        $VMDetail | Where-Object { $_.'VM Tools Status' -ne 'OK' } | Set-Style -Style Warning -Property 'VM Tools Status'
                                                    }
                                                    if ($Healthcheck.VM.PowerState) {
                                                        $VMDetail | Where-Object { $_.'Power State' -ne 'On' } | Set-Style -Style Warning -Property 'Power State'
                                                    }
                                                    if ($Healthcheck.VM.ConnectionState) {
                                                        $VMDetail | Where-Object { $_.'Connection State' -ne 'Connected' } | Set-Style -Style Critical -Property 'Connection State'
                                                    }
                                                    if ($Healthcheck.VM.CpuHotAdd) {
                                                        $VMDetail | Where-Object { $_.