Achievements

Advertisements

Finding a VM’s Port-ID with PowerCLI

A question was recently brought up over finding a VM’s Port-ID with PowerCLI.

Right off the bat, I assumed the ask was for the distributed switch port. That wasn’t the case though. In this situation, the ask was to identify the Port-ID that was being displayed in ESXTOP via the Network view.

Example:

The Port-ID that’s being displayed is local to the host. That information isn’t available through the VM object, at least as far as I could find. In order to get the Port-ID through PowerCLI, we have to get a little crafty. This is going to require some ESXCLI usage.

It can be used in a couple different ways, so use it however makes sense to you.

Example Usage:

After feeding in a VM by pipeline, making use of the VM parameter, and even passing multiple VMs to the script, we can see how the Port-ID does in fact match up with what’s displayed in the ESXTOP example from above.