amolnjadhav
Enthusiast
Enthusiast

Need help to retrive Distributed virtual switch name along with Pswitch stats.

Jump to solution

I have referred VMware KB article to get below power-cli code to get physical switch information via cdp.. I am looking for similar output along with DVS Name. Something look like this.. I couldn't able to find the solution hence need help on this..

VMHost VMNic DVS-Name DevId Address PortId HardwarePlatform

------ ----- ----- ------- ------ ----------------

esxhostname vmnic0 DVS-123 esx1.mon.com 1.1.1.1 GigabitEthernet1/0/9 cisco WS-C3750G-24TS-1U

param($VMHost)
$vmh = Get-VMHost $VMHost
If ($vmh.State -ne "Connected") {
Write-Output "Host $($vmh) state is not connected, skipping."
}
Else {
Get-View $vmh.ID | `
% { $esxname = $_.Name; Get-View $_.ConfigManager.NetworkSystem} | `
% { foreach ($physnic in $_.NetworkInfo.Pnic) {
$pnicInfo = $_.QueryNetworkHint($physnic.Device)
foreach( $hint in $pnicInfo ){
# Write-Host $esxname $physnic.Device
if ( $hint.ConnectedSwitchPort ) {
$hint.ConnectedSwitchPort | select @{n="VMHost";e={$esxname}},@{n="VMNic";e={$physnic.Device}},DevId,Address,PortId,HardwarePlatform
}
else {
Write-Host "No CDP information available."
}
}
}
}
}

For example, if this script is saved as Get-mVMHostCDPInfo.ps1 :

# Get-mVMHostCDPInfo.ps1 -VMHost esxhostname | ft -a

VMHost VMNic DevId Address PortId HardwarePlatform
------ ----- ----- ------- ------ ----------------
esxhostname vmnic0 esx1.mon.com 1.1.1.1 GigabitEthernet1/0/9 cisco WS-C3750G-24TS-1U

Please consider marking this answer "correct" or "helpful" if you think your query have been answered correctly. Regards Amol Jadhav VCP NSXT | VCP NSXV | VCIX6-NV | VCAP-DCA | CCNA | CCNP - BSCI
1 Solution

Accepted Solutions
LucD
Leadership
Leadership

Did you already check out Report VMHost, VMNIC, DVS and CDP info


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
4 Replies
LucD
Leadership
Leadership

I'm not sure I understand what you are trying to do.

The CDP information concerns information from a physical NIC.

A VDS is a virtual concept of a switch.

This would only make sense if you retrieve the CDP information for the pNIC that are connected to the VDS.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

amolnjadhav
Enthusiast
Enthusiast

Hi LucD,

Thanks for your reply.

Yes, i understand CDP to fetch the information from physical NIC.

Customer has many ESX hosts.. Each esx host has around 5-6 physical nic cards.. those NIC cards maps to different distributed switches.
Hence customer wants to know vmnicX connected to which Physical switch and which distributed virtual switch. i know its strange requirement.

Example,

He wants to see the output like this.

VMHost VMNic DVS-Name DevId Address PortId HardwarePlatform

------ ----- ----- ------- ------ ----------------

esx1 vmnic0 DVS-123 esx1.mon.com 1.1.1.1 GigabitEthernet1/0/9 cisco WS-C3750G-24TS-1U

Please consider marking this answer "correct" or "helpful" if you think your query have been answered correctly. Regards Amol Jadhav VCP NSXT | VCP NSXV | VCIX6-NV | VCAP-DCA | CCNA | CCNP - BSCI
0 Kudos
LucD
Leadership
Leadership

Did you already check out Report VMHost, VMNIC, DVS and CDP info


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
amolnjadhav
Enthusiast
Enthusiast

Thanks for the link.. This is the one i was looking for..

Please consider marking this answer "correct" or "helpful" if you think your query have been answered correctly. Regards Amol Jadhav VCP NSXT | VCP NSXV | VCIX6-NV | VCAP-DCA | CCNA | CCNP - BSCI
0 Kudos