1 Reply Latest reply on Jul 11, 2012 5:21 AM by LucD

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

    TomHowarth Guru
    User ModeratorsvExpert

      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

        • 1. Re: Script to obtain all portgroups in a Datacenter and their VLAN ID
          LucD Guru
          vExpertUser ModeratorsCommunity Warriors

          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
               }     }   }}