Leveraging the vSphere API cookbook in PowerCLI

If you have ever run into an issue with PowerCLI where you can find the information you need in the API guide but not a cmdlet to report the info? Here is one walk through of how I got my groove back tracked down the info I needed.

I found myself, as I often do, wandering the rain washed beaches in South Florida wondering how to figure out from PowerCLI the Network Resource Pool assigned to a given Distributed PortGroup.

A perusal of the latest PowerCLI update showed some new cmdlets but none of them report on the NRPs – even at the dVS level.

I did find that the net-dvs command from ESXi would report the dVS info like this:

com.vmware.common.port.respools.cfg:
NRP_30717_dvs-421:50:-1:2

Although it would seem a little cryptic w/o the user-defined name and didn’t link back to a portgroup. It did list the QoS tag (the last integer on the second line) tho so that was something.

I noticed in the API there was a Managed Object – Vmware Distributed Virtual Switch which had a networkResourcePool property. That sounded promising, now what?

I started digging through blog after blog about accessing the API via PowerCLI and finally I just started playing at the PowerCLI prompt using the Get-View cmdlet Alan and Luc rave about.

For those of you playing along at home, the $vds.networkresporcepool is an array – the eight defaults plus my custom one. The [8] tells PowerShell to use the ninth member of the array. And there is my QoS / PriorityTag.

One liner, retrieving the QoS or PriorityTag of a specific Resource Pool on a specific vDS:

Now to figure out what PortGroups use it. I dug all over the API and finally found the networkResourcePoolKey which was a property of a DVPortSetting. However, that is a property for a specific port, surely the portgroup has it set at some level? I then noticed that the DVPortSetting was a property of several objects, including DVSConfigSpec – which turned out to hold the default information for a given dVS including a DVPortSetting which is used for the default settings for all ports.

Using a technique as above – assigning a Get-View of the object to a variable and then drilling into it, I arrived at a oneliner to return the “Key” of the ResourcePool associated with a given portgroup (note that -1 is returned if none is configured)