VMware ESXi – Get VM’s by VLAN ID with PowerCLI

Often when when working in large environments you’ll get interesting requests. These may be to assist in troubleshooting, auditing, reporting or any other reason.

I was recently requested to provide a list of mac addresses for every VM with a vNIC in a specific vlan.

I had a feeling this was going to be a repeated request (for various vlans) so presented a good opportunity to script it.

Finding a mac address for a particular vm is straightforward;

10-05-2016 12-06-55 AM

and of course, this can be expanded to a  Cluster, Host etc;

9-05-2016 11-53-50 PM

9-05-2016 11-56-31 PM

Getting all the VM’s on a specified VLAN and including the required details is not that straightforward, but certainly not that difficult.  Here’s how I went about it for VLAN ID 2591;

10-05-2016 2-07-06 PM

Note that a blank MacAddress field indicates the VM is simply powered off.

 

Related Post

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: