I did some experimenting, and I think $vds.ExtensionData.Summary.VM.Count is not a correct value for the number of ports used.
Especially if a VM has more than 1 vNIC connected to a portgroup on that VDS.
I came up with the following (it shows the name of the VDS and the number of used ports (by VMs) over the total number of ports).
foreach($vds in Get-View -ViewType VmwareDistributedVirtualSwitch){
$pgKeys = $vds.Portgroup.Value
$nics = Get-View -Id $vds.Summary.vm | %{
$_.Config.Hardware.Device |
where{$_ -is [VMware.Vim.VirtualEthernetCard] -and $pgKeys -Contains $_.Backing.Port.PortgroupKey}
}
"$($vds.Name): $($nics.Count)/$($vds.Config.NumPorts)"
}
Can you check if that gives the correct values in your environment?
Also note that this does not yet take into account the number of ports used by the Uplinks.