VMware PowerCLI

The Best User Interface for your VMware Datacenter!

Adding cmdlets to retreive information about vGPUs attached to vms

It would be really great to have some cmdlets to retrieve some information about vGPUs. Because now if you added an vGPU to your vm there is no easy way to see if your vm has a vGPU attached, Of course you can log in to your ESXi host and run nvidia-smi. But would it be great to do such things with PowerCLI.

 

I created some code:

This is the output if you run the code. You retrieve a list and you can see easily if your vm has a vGPU attached or not

 

PowerCLI C:\> Get-vGPUlist -VMhost esx1
 
Name   vGPUprofile
----   -----------
vm1 grid_m60-2a
vm2 grid_m60-2a
vm3 grid_m60-2a
vm4 grid_m60-2a
vm5 grid_m60-2a
vm6 grid_m60-2a
vm7 grid_m60-2a
vm8 grid_m60-2a
vm9 grid_m60-2a
vm10 
vm11 grid_m60-2a
vm12 grid_m60-2a
vm13 grid_m60-2a
vm14 grid_m60-2a
vm14 grid_m60-2q
 
here is the code:
 
Function Get-vGPUlist{

    Param (
         $Cluster,
         $VMhost
         
    )

    If ($cluster){
        $VMs = get-cluster -name $cluster | get-vm
        }

    If($vmhost){
        $VMs = get-vmhost -name $vmhost | get-vm
        }

 
    
    $output=@()
    foreach ($VM in $VMs){

    $object = New-Object PSObject
    Add-Member -InputObject $object NoteProperty Name $VM.Name

    $vGPUDevice = $VM.ExtensionData.Config.hardware.Device  | where {$_.Backing.Vgpu}
    Add-Member -InputObject $object NoteProperty vGPUprofile $vGPUDevice.Backing.Vgpu

    $output+= $object
    }
    
    $output | sort-object vGPUprofile

    }
 
 
  • Gemma van der Voorst
  • Sep 12 2017
  • Looking for Feedback
  • Attach files
  • Deleted User commented
    September 19, 2017 14:33

    Gemma, Is this code in powercli-example-scripts? It should be! :)