-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathGet-VMHostUplinkDetails.psm1
144 lines (120 loc) · 5.59 KB
/
Get-VMHostUplinkDetails.psm1
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
function Get-VMHostUplinkDetails {
<#
.NOTES
===========================================================================
Created by: Markus Kraus
===========================================================================
Changelog:
2017.03 ver 1.0 Base Release
2020.03 ver 1.1 Add LLDP Support
===========================================================================
External Code Sources:
Get-CDP Version from @LucD22
https://communities.vmware.com/thread/319553
LLDP PowerCLI Tweak
https://tech.zsoldier.com/2018/05/vmware-get-cdplldp-info-from.html
===========================================================================
Tested Against Environment:
vSphere Version: vSphere 6.7 U3
PowerCLI Version: PowerCLI 11.5
PowerShell Version: 5.1
OS Version: Server 2016
Keyword: ESXi, Network, CDP, LLDP, VDS, vSwitch, VMNIC
===========================================================================
.DESCRIPTION
This Function collects detailed informations about your ESXi Host connections to pSwitch and VDS / vSwitch.
LLDP Informations might only be available when uplinks are connected to a VDS.
.Example
Get-VMHost -Name MyHost | Get-VMHostUplinkDetails -Type LLDP | Where-Object {$_.VDS -ne "-No Backing-"} | Format-Table -AutoSize
.Example
Get-VMHost -Name MyHost | Get-VMHostUplinkDetails -Type CDP | Where-Object {$_.VDS -ne "-No Backing-"} | Sort-Object ClusterName, HostName, vmnic | Format-Table -AutoSize
.Example
Get-Cluster -Name MyCluster | Get-VMHost | Get-VMHostUplinkDetails -Type LLDP | Format-Table -AutoSize
.Example
Get-Cluster -Name MyCluster | Get-VMHost | Get-VMHostUplinkDetails -Type CDP | Format-Table -AutoSize
.PARAMETER myHosts
Hosts to process
#Requires PS -Version 5.0
#Requires -Modules VMware.VimAutomation.Core, @{ModuleName="VMware.VimAutomation.Core";ModuleVersion="6.3.0.0"}
#>
[CmdletBinding()]
param(
[Parameter(Mandatory=$True, ValueFromPipeline=$True, Position=0, HelpMessage = "Specifies the hosts for which you want to retrieve the uplink details.")]
[ValidateNotNullorEmpty()]
[Alias("myHosts")]
[VMware.VimAutomation.Types.VMHost[]] $VMHost,
[Parameter(Mandatory=$True, ValueFromPipeline=$False, Position=1, HelpMessage = "Type of infos you want to collect (CDP / LLDP)")]
[ValidateSet("CDP","LLDP")]
[String] $Type
)
Begin {
function Get-Info ($VMhostToProcess){
$VMhostProxySwitch = $VMhostToProcess.NetworkInfo.ExtensionData.ProxySwitch
$VMhostSwitch = $VMhostToProcess.NetworkInfo.VirtualSwitch
$objReport = @()
$VMhostToProcess| ForEach-Object{Get-View $_.ID} |
ForEach-Object{ Get-View $_.ConfigManager.NetworkSystem} |
ForEach-Object{ foreach($physnic in $_.NetworkInfo.Pnic){
if($Type -eq "CDP"){
$obj = "" | Select-Object ClusterName,HostName,vmnic,PCI,MAC,VDS,vSwitch,CDP_Port,CDP_Device,CDP_Address
}
elseif($Type -eq "LLDP"){
$obj = "" | Select-Object ClusterName,HostName,vmnic,PCI,MAC,VDS,vSwitch,LLDP_Port,LLDP_Chassis,LLDP_SystemName
}
else {
Throw "Invalide Type"
}
$pnicInfo = $_.QueryNetworkHint($physnic.Device)
foreach($hint in $pnicInfo){
$obj.ClusterName = $VMhostToProcess.parent.name
$obj.HostName = $VMhostToProcess.name
$obj.vmnic = $physnic.Device
$obj.PCI = $physnic.PCI
$obj.MAC = $physnic.Mac
if ($backing = ($VMhostProxySwitch | Where-Object {$_.Spec.Backing.PnicSpec.PnicDevice -eq $physnic.Device})) {
$obj.VDS = $backing.DvsName
}
else {
$obj.VDS = "-No Backing-"
}
if ($backing = ($VMhostSwitch | Where-Object {$_.Nic -eq $physnic.Device})) {
$obj.vSwitch = $backing.name
}
else {
$obj.vSwitch = "-No Backing-"
}
if($Type -eq "CDP"){
if( $hint.ConnectedSwitchPort ) {
$obj.CDP_Port = $hint.ConnectedSwitchPort.PortId
$obj.CDP_Device = $hint.ConnectedSwitchPort.DevId
$obj.CDP_Address = $hint.ConnectedSwitchPort.Address
}
else {
$obj.CDP_Port = "-No Info-"
$obj.CDP_Device = "-No Info-"
$obj.CDP_Address = "-No Info-"
}
}
if($Type -eq "LLDP"){
if( $hint.LldpInfo ) {
$obj.LLDP_Port = $hint.LldpInfo.PortId
$obj.LLDP_Chassis = $hint.LldpInfo.ChassisId
$obj.LLDP_SystemName = ($hint.LldpInfo.Parameter | Where-Object key -eq "System Name").Value
}
else {
$obj.LLDP_Port = "-No Info-"
$obj.LLDP_Chassis = "-No Info-"
$obj.LLDP_SystemName = "-No Info-"
}
}
}
$objReport += $obj
}
}
$objReport
}
}
Process {
$VMHost | Foreach-Object { Write-Output (Get-Info $_) }
}
}