VMware Cloud Community
Pilu1978
Enthusiast
Enthusiast

VMnic details of VDSwicth

Hi,

I would like to find out the vmnics connected to a distributed vswitch using powercli.

Please help.

Tags (1)
3 Replies
LucD
Leadership
Leadership

Try like this

$report = @()

foreach ($sw in (Get-VirtualSwitch -Distributed)) {

   $uuid = $sw.ExtensionData.Summary.Uuid

   $sw.ExtensionData.Config.Host | % {

   $portStates = $sw.ExtensionData.FetchDVPorts($null)

   $esx = Get-View $_.Config.Host

   $netSys = Get-View $esx.ConfigManager.NetworkSystem

   $netSys.NetworkConfig.ProxySwitch | where {$_.Uuid -eq $uuid} | % {

   foreach ($pnicSpec in $_.Spec.Backing.PnicSpec) {

   $row = "" | Select Host, dvSwitch, PNic, PortLinkUp

   $row.Host = $esx.Name

   $row.dvSwitch = $sw.Name

   $row.PNic = $pnicSPec.PnicDevice

   $row.PortLinkUp = ($portStates | where {$_.Key -eq $pnicSPec.UplinkPortKey}).State.RunTimeInfo.LinkUp

   $report += $row

   }

   }

   }

}


$report


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

mark49808
Enthusiast
Enthusiast

Old thread but i'm curious as its exactly what i need.

Seems to work on some of my vcenters, but others i get:

Get-View : 5/21/2021 3:02:35 PM Get-View View with Id 'HostSystem-host-56013' was not found on the server(s).

 

This seems to be the problematic line:
$esx = Get-View $_.Config.Host

Running 6.7...not sure why this is bombing out.

Edit: Disregard i had to specify the -server command as i was connected to multiple viservers. Leaving this here for the next person.

Reply
0 Kudos
LucD
Leadership
Leadership

I suspect you are connected to multiple vCenters.
Check if $global:defaultVIServers contains more than 1 entry.


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

Reply
0 Kudos