Thanks Jason! I was just logging on to update the post with the same article that you did.
My co-worker, Matt Wahl, modified the script to accommodate having two GRID cards in the host. The modified script is below. I understand that the original script is written for one GRID card.
The script does not yet work for passthrough and we are looking into that. We are going to try the Onyx fling to try to determine the commands used to assign passthrough. Home | VMware Flings.
[CmdletBinding()]
Param (
[parameter(Mandatory=$true)]
[string]$HostIP,
[Parameter(Mandatory=$True)]
[string]$GPUProf,
[Parameter(Mandatory=$True)]
[string]$VMname
)
Function Get-GPUProfile {
Param ($vmhost)
$VMhost = Get-VMhost $VMhost
$vmhost.ExtensionData.Config.SharedPassthruGpuTypes
}
Function Get-vGPUDevice {
Param ($vm)
$VM = Get-VM -name $VMname
$vGPUDevice = $VM.ExtensionData.Config.hardware.Device | Where {$.backing.vgpu}
$vGPUDevice | Select Key, ControllerKey, Unitnumber, @{Name="Device";Expression={$.DeviceInfo.Label}}, @{Name="Summary";Expression={$_.DeviceInfo.Summary}}
}
Function Remove-vGPU {
Param (
[Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true,Position=0)] $VM,
[Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true,Position=1)] $vGPUDevice
)
$ControllerKey = $vGPUDevice.controllerKey
$key = $vGPUDevice.Key
$UnitNumber = $vGPUDevice.UnitNumber
$device = $vGPUDevice.device
$Summary = $vGPUDevice.Summary
$VM = Get-VM $VM
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$spec.deviceChange = New-Object VMware.Vim.VirtualDeviceConfigSpec[] (1)
$spec.deviceChange[0] = New-Object VMware.Vim.VirtualDeviceConfigSpec
$spec.deviceChange[0].operation = 'remove'
$spec.deviceChange[0].device = New-Object VMware.Vim.VirtualPCIPassthrough
$spec.deviceChange[0].device.controllerKey = $controllerkey
$spec.deviceChange[0].device.unitNumber = $unitnumber
$spec.deviceChange[0].device.deviceInfo = New-Object VMware.Vim.Description
$spec.deviceChange[0].device.deviceInfo.summary = $summary
$spec.deviceChange[0].device.deviceInfo.label = $device
$spec.deviceChange[0].device.key = $key
$_this = $VM | Get-View
$nulloutput = $_this.ReconfigVM_Task($spec)
}
Function New-vGPU {
Param ($VM, $vGPUProfile)
$VM = Get-VM $VM
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$spec.deviceChange = New-Object VMware.Vim.VirtualDeviceConfigSpec (1)
$spec.deviceChange[0] = New-Object VMware.Vim.VirtualDeviceConfigSpec
$spec.deviceChange[0].operation = ‘add’
$spec.deviceChange[0].device = New-Object VMware.Vim.VirtualPCIPassthrough
$spec.deviceChange[0].device.deviceInfo = New-Object VMware.Vim.Description
$spec.deviceChange[0].device.deviceInfo.summary = ‘’
$spec.deviceChange[0].device.deviceInfo.label = ‘New PCI device’
$spec.deviceChange[0].device.backing = New-Object VMware.Vim.VirtualPCIPassthroughVmiopBackingInfo
$spec.deviceChange[0].device.backing.vgpu = "$vGPUProfile"
$vmobj = $VM | Get-View
$reconfig = $vmobj.ReconfigVM_Task($spec)
if ($reconfig) {
$ChangedVM = Get-VM $VM
$vGPUDevice = $ChangedVM.ExtensionData.Config.hardware.Device | Where { $.backing.vgpu}
$vGPUDevice | Select Key, ControllerKey, Unitnumber, @{Name="Device";Expression={$.DeviceInfo.Label}}, @{Name="Summary";Expression={$_.DeviceInfo.Summary}}
}
}
$VMHost = Get-VMHost $HostIP
$vGPUProfile = Get-GPUProfile -vmhost $VMHost
Write-Host "The following vGPU Profiles are available to choose for this host"
$vGPUProfile
Choose a profile to use from the list
$ChosenvGPUProfile = $vGPUProfile | Where {$_ -like "$GPUProf" }
write-host "CHOSEN GPU PROFILE :: $ChosenvGPUProfile"
Get a VM to add it to
$VM = Get-VM $VMname
Write-Host "Adding the vGPU to $vm"
New-vGPU -VM $vm -vGPUProfile $ChosenvGPUProfile
At a later date
Read-Host "The device has been added, press enter to remove again"
Write-Host "Removing the GPU Devices in $VM"
Remove-vGPU -VM $vm -vGPUDevice (Get-vGPUDevice -vm $VM)