This is probably too much, but includes the connected VMs.
Get-VirtualPortGroup |
Select Name,
@{N='Host';E={
if($_ -is [VMware.VimAutomation.ViCore.Impl.V1.Host.Networking.DistributedPortGroupImpl]){
[string]::Join(',',(Get-View -Id $_.ExtensionData.Host -Property Name | %{$_.Name}))
}
else{
Get-View -Id $_.VMHostId | Select -ExpandProperty Name
}}},
@{N='SwitchType';E={
if($_ -is [VMware.VimAutomation.ViCore.Impl.V1.Host.Networking.DistributedPortGroupImpl]){
'VDS'
}
else{'VSS'}}},
@{N='VLANType';E={
if($_ -is [VMware.VimAutomation.ViCore.Impl.V1.Host.Networking.DistributedPortGroupImpl]){
switch($_.ExtensionData.Config.DefaultPortConfig.Vlan.GetType().Name){
'VmwareDistributedVirtualSwitchPvlanSpec' {'PvLAN'}
'mwareDistributedVirtualSwitchVlanIdSpec' {'VLAN'}
'VmwareDistributedVirtualSwitchTrunkVlanSpec' {'VLAN Trunking'}
Default {'None'}
}
}
else{
$_.ExtensionData.GetType().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='Available ports';E={
if($_ -is [VMware.VimAutomation.ViCore.Impl.V1.Host.Networking.DistributedPortGroupImpl]){
$_.numPorts - $_.ExtensionData.Vm.Count
}
else{'na'}}},
@{N='Total ports';E={
if($_ -is [VMware.VimAutomation.ViCore.Impl.V1.Host.Networking.DistributedPortGroupImpl]){
$_.NumPorts
}
else{'na'}}},
@{N='VM';E={(Get-View -Id $_.ExtensionData.VM -Property Name | %{$_.Name}) -join '|'}}