VMware Cloud Community
Ritam9
Contributor
Contributor

Need scritp to get the Switch information

Hi ,

I am new to powercli.  I am looking for a script which can give me the information of the physical switch  which is connected with the esxi host

Thanks in advance.

0 Kudos
3 Replies
LucD
Leadership
Leadership

I assume you are referring to the QueryNetworkHint method to get the physical switch information ?

To see if I got the question right, you want to

  • determine the ESXi nodes connected to the distributed switch
  • determine for each host the physical nics connected to the distributed switch
  • use QueryNetworkHint with each pnic to get the switch info

Is that correct ?


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

0 Kudos
LucD
Leadership
Leadership

Try something like this

$clusterName = 'MyCluster'

$cluster = Get-Cluster -Name $clusterName

foreach($esx in Get-VMHost -State Connected -Location $cluster){

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

  $esxcli = Get-EsxCli -VMHost $esx

  foreach($vds in Get-VDSwitch -VMHost $esx){

    foreach($pnic in ($esxcli.network.vswitch.dvs.vmware.list($vds.Name) | Select -ExpandProperty Uplinks)){

      $netSys.QueryNetworkHint($pnic) |

      Select @{N='Cluster';E={$cluster.Name}},

        @{N='VMHost';E={$esx.Name}},

        @{N='VDS';E={$vds.Name}},

        @{n='pNIC';E={$pnic}},

        @{N='MgmtIP';E={$_.LLDPInfo.Parameter | where{$_.Key -eq 'Management Address'} | Select -ExpandProperty Value}},

        @{N='PortDesc';E={$_.LLDPInfo.Parameter | where{$_.Key -eq 'Port Description' } | Select -ExpandProperty Value}},

        @{N='SysDesc';E={$_.LLDPInfo.Parameter | where{$_.Key -eq 'System Description' } | Select -ExpandProperty Value}},

        @{N='SysName';E={$_.LLDPInfo.Parameter | where{$_.Key -eq 'System Name' } | Select -ExpandProperty Value}}

    }

  }

}


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

0 Kudos
Ritam9
Contributor
Contributor

Thanks Again @LucD.

I will let you know the result.  Let me try it 🙂

0 Kudos