I’m a noob when it comes to PowerCLI, I can Get-VM like most everyone else, but not much more. You may have seen my previous post about Taking Back Resources where I talked about the theory and logic behind vGPU cycle harvesting. Right now I’m working on putting it into action and the best way I can think of is a PowerCLI script.
If you try googling much on GPU options for PowerCLI you’re not likely to find much. Either that or I am using the wrong terms. So before I drop some cool cycle harvesting options out there for folks I want to share two PowerCLI commands to look at GPU functions in your environment.
The first command I’d like to share is seeing what vGPU profile is being used by a VM. This is a two part command. First you assign a VM to a variable, then you can explore the VMs backing. I figured it out from reading through code on the rgel/PowerCLi GitHub (https://github.com/rgel/PowerCLi/blob/master/Vi-Module/Vi-Module.psm1) My thanks to Roman and Hans for sharing this wonderful code.
PS C:\> $MyVMs = Get-VM "VMname" PS C:\> $MyVMs.ExtensionData.Config.Hardware.Device.Backing.vgpu grid_p4-4q
Yup, thats all there is to finding out what vGPU profile a VM is using.
Now for the next bit of goodness. Finding out what graphics cards are in a given host.
PS C:\> Get-VMHost | Get-VMHostPciDevice -DeviceClass DisplayController VMHost.Name Name DeviceClass ----------- ---- ----------- esxi02.wondernerd... NVIDIA Corporation NVIDIATesla P4 DisplayController esxi02.wondernerd... Matrox Electronics Systems Ltd. MGA G200e [Pilot] ServerEngines (SEP1) DisplayController esxi01.wondernerd... Matrox Electronics Systems Ltd. PowerEdge R610 MGA G200eW WPCM450 DisplayController
Taking it a step further lets isolate this to the P4 in my environment. To do this we’ll modify the above just a bit…
PS C:\> Get-VMHost | Get-VMHostPciDevice -deviceClass DisplayController -Name "NVIDIA*" VMHost.Name Name DeviceClass ----------- ---- ----------- esxi02.wondernerd... NVIDIA Corporation NVIDIATesla P4 DisplayController
I found this by poking around the PowerCLI Cmdlet Reference and playing with the output. (https://code.vmware.com/docs/7336/cmdlet-reference#/doc/Get-VMHostPciDevice.html)
Hope this helps as you develop your PowerCLI scripts dealing with vGPUs.