Today I was busy with PowerCLI and dvPort groups. I started to use the Get-VirtualPortgroup –Distributed cmdlet and parameter to retrieve some information about the dvPort group. But the default output doesn’t show the VlanId. See the screen shot below for the default output.
I don’t know if this is a known issue between PowerCLI 5.1 release 1 and vSphere 4.1 update 2. So I have to test it in a vSphere 5 environment.
But how can you find the vlanid of a distributed portgroup? You can use a PowerCLI script which I created to fix this little “bug” and I have also added the PortsFree column to the output of the script.
$dvPortgroup = get-virtualportgroup -Distributed -Name "vlan1" $dvPortgroupInfo = New-Object PSObject -Property @{ Name = $dvPortgroup.Name Key = $dvPortgroup.Key VlanId = $dvPortgroup.ExtensionData.Config.DefaultPortConfig.Vlan.VlanId Portbinding = $dvPortgroup.Portbinding NumPorts = $dvPortgroup.NumPorts PortsFree = ($dvPortgroup.ExtensionData.PortKeys.count - $dvPortgroup.ExtensionData.vm.count) } $dvPortgroupInfo | ft -AutoSize
The output of the script:
If you want to create a report of all the dvPort groups. You can use the following script to achieve that goal:
$info = @() foreach($dvPortgroup in (Get-VirtualPortgroup -Distributed | Sort Name)){ $dvPortgroupInfo = New-Object PSObject -Property @{ Name = $dvPortgroup.Name Key = $dvPortgroup.Key VlanId = $dvPortgroup.ExtensionData.Config.DefaultPortConfig.Vlan.VlanId Portbinding = $dvPortgroup.Portbinding NumPorts = $dvPortgroup.NumPorts PortsFree = ($dvPortgroup.ExtensionData.PortKeys.count - $dvPortgroup.ExtensionData.vm.count) } $info += $dvPortgroupInfo } $info | Export-Csv -UseCulture -NoTypeInformation C:\tmp\dvportgroup_info.csv
I found your post because I was having the same issue in vCenter 5.1B so its an error that continues to propagate.