$myCol = @()
ForEach ($VMHost in (Get-VMHost | Sort Name))
{
ForEach ($VM in ($VMHost | Get-VM))
{
ForEach ($NIC in (Get-NetworkAdapter -VM $VM))
{
$myObj = "" | Select VMHost, VM, NIC, PortGroup, vSwitch
$myObj.VMHost = $VMHost.Name
$myObj.VM = $VM.Name
$myObj.NIC = $NIC.Name
$myObj.PortGroup = Get-VirtualPortGroup -VM $VM -Name $NIC.NetworkName
$myObj.vSwitch = $myObj.PortGroup.VirtualSwitchName
$myCol += $myObj
}
}
}
$myCol | Group-Object VMHost, vSwitch -NoElement | Sort Name | Select Name, Count