VMware Cloud Community
TimA1
Contributor
Contributor

PowerCLI and Networking

I have a simple request...I hope.

I need a script that will dump to CSV, the following properties.  Port Group VLAN ID and the Number of VMs in membership.  I need it to be from the Distributed Virtual Switch.  But I don't know enough of PowerCLI.  Here is where I have gotten so far.

$gports = Get-VirtualSwitch -Name MyDVSwitch | Get-VirtualPortGroup | Select Name

0 Kudos
2 Replies
LucD
Leadership
Leadership

Try like this

Get-VirtualPortGroup -Distributed |

Select Name,

  @{N='VlanId';E={

   if($_ -is [VMware.VimAutomation.ViCore.Impl.V1.Host.Networking.DistributedPortGroupImpl]){

   if($_.ExtensionData.Config.DefaultPortConfig.Vlan -is [VMware.Vim.VmwareDistributedVirtualSwitchPvlanSpec]){

   $_.ExtensionData.Config.DefaultPortConfig.Vlan.PvlanId

  }

   elseif($_.ExtensionData.Config.DefaultPortConfig.Vlan -is [VMware.Vim.VmwareDistributedVirtualSwitchVlanSpec]){

   if($_.ExtensionData.Config.DefaultPortConfig.Vlan.VlanId -is [VMware.Vim.NumericRange[]]){

   [string]::Join(',',($_.ExtensionData.Config.DefaultPortConfig.Vlan.VlanId | %{"$($_.Start)-$($_.End)"}))

  }

   else{

   $_.ExtensionData.Config.DefaultPortConfig.Vlan.VlanId

  }

  }

  }

   else{$_.VlanId}}},

  @{N='VMConnected';E={$_.ExtensionData.Vm.Count}} |

Sort-Object -Property Name -Unique


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

0 Kudos
TimA1
Contributor
Contributor

Perfect!!

Thank You...Another satisfied User!!

0 Kudos