Which VMs are in which Port Groups

This took me a little while to get sorted as I had a gap in my PowerShell knowledge around the handling and formating of nested objects. A bit of exploration with get-member and I came up witha working script. It’s based on a post by Hugo Peeters and lists the VMs that are connected to (or belong to) a particular Port Group.

I wanted to know this as I was producing some infrastructure diagrams for a customer and wanted to know the names of VMs in a cluster for each Port Group without having to visit each ESX server.

The script is Get-VMPortGroups.ps1

Just call it and it will return a list of Port Groups and the VMs that belong to each. As an option, add a filter parameter to work with specific Port Groups. For example:

Get-VMPortGroups.ps1 “My Port Group”

or

Get-VMPortGroups.ps1 “*Development”

Sorry if the script source is a bit long or clunky. I was having a bad day when I wrote it and made tonnes of silly mistakes.

Michael is a Senior Consultant for Xtravirt. If it's got buttons or flashy lights on it then it'll probably be on his radar. When not "mending computers" (it's sometimes easier than explaining "cloud" to relatives), Michael provides essential education, entertainment and trampoline services to his two children.

Leave a Reply

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