PowerShell: List All Hyper-V Virtual Machines Along With The Connected Switch

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:

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

There you have it!  Told you it was easy 😉