PowerCLI command to list all PortGroups on an ESX/ESXi host

A Lead Engineer asked me to send him a list of all PortGroups on a specific ESX host (running ESX 4.1). Due to the time and effort required to obtain this info manually, I had to use PowerCLI. I ran the command below:

Get-VirtualPortGroup -VMHost esx1 | select Name, VirtualSwitch, VLanId

It outputs results similar to the below:

Name                     VirtualSwitch      VLanId
----                     -------------      ------
DMZ-VLAN                 vSwitch0           1139
Inside-VLAN              vSwitch0           805
VMNet                    vSwitch1           0
VMNet-KS                 vSwitch1           124
VMNet-SC                 vSwitch1           0
VMNet-vmk                vSwitch1           0
Backup-Inside-VLAN       vSwitch2           648
Backup-DMZ-VLAN          vSwitch2           647

To get the results in a spreadsheet export the results to a csv file per the below:

Get-VirtualPortGroup -VMHost esx1 | select Name, VirtualSwitch, VLanId | | Export-Csv C:\VMHostNetworkInfo.csv

The full command line reference for Get-VirtualPortGroup is available here.

  • Rajesh Bhuvanan

    Is there any way to have list like below.
    VMHostname, VLAN NAme, VirtualSwitch, VLan ID