VMware Cloud Community
TomHowarth
Leadership
Leadership

Script to obtain all portgroups in a Datacenter and their VLAN ID

Hi Powershell Guru's

I need a script to gather all the port groups in a DataCenter, both on Standard Switches and DVswitches. this needs to be coupled with the VLAN ID as well

Tom Howarth VCP / VCAP / vExpert
VMware Communities User Moderator
Blog: http://www.planetvm.net
Contributing author on VMware vSphere and Virtual Infrastructure Security: Securing ESX and the Virtual Environment
Contributing author on VCP VMware Certified Professional on VSphere 4 Study Guide: Exam VCP-410
0 Kudos
1 Reply
LucD
Leadership
Leadership

Try something like this

Get-Datacenter -Name MyDatacenter | 
Get-VirtualPortGroup
| Select Name, @{N="VlanId";E={     if($_.ExtensionData -is [VMware.Vim.HostPortGroup]){$_.VLanId}     else{       $t = $_.Extensiondata.Config.DefaultPortConfig.Vlan
      if($t.VlanId.Count){         $t.VlanId | %{           $_.Start.ToString() + "-" + $_.End.ToString()         }       }       elseif($t.Pvlanid){         $t.PvlanId
      }      
else{         $t.VlanId
     }     }   }}


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

0 Kudos