Here is a useful PowerShell script, that I have used and is fairly easy to figure, but as ever I like to make a note of it somewhere so this is a good a place as any.  So my issue was initially that I wanted to find out which of my VM’s were connected to a particular network Switch.  Due to recently implementing a Cisco UCS, we have two Virtual Machine NIC – one on each Fabric Interconnect which connects to our Core Switch.  Each VM (depending on whether it is odd or even numbered) will have a connection to the Core Network on either the 10GB uplink on Fabric A or Fabric B.

Here is a nice little one liner:

Get-VM | Get-VMNetworkAdapter | ? {$_.SwitchName -eq "VM-SWITCH-A"} | FT VMName, SwitchName -AutoSize

I then thought, it would be nice if it could count the number of VM’s on that particular Switch…  Again very easy:

Get-VM | Get-VMNetworkAdapter | ? {$_.SwitchName -eq "VM-SWITCH-A"} | Measure

There you have it!  Told you it was easy 😉