Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save victor141516/64672cd11621586064b8dcd61b39ee8d to your computer and use it in GitHub Desktop.
Save victor141516/64672cd11621586064b8dcd61b39ee8d to your computer and use it in GitHub Desktop.
change-vm-gpu.bat
function Assign-VMGPUPartitionAdapter {
param(
[string]$VMName,
[string]$GPUName,
[decimal]$GPUResourceAllocationPercentage = 100
)
$PartitionableGPUList = Get-WmiObject -Class "Msvm_PartitionableGpu" -ComputerName $env:COMPUTERNAME -Namespace "ROOT\virtualization\v2"
if ($GPUName -eq "AUTO") {
$DevicePathName = $PartitionableGPUList.Name[0]
Add-VMGpuPartitionAdapter -VMName $VMName
}
else {
$DeviceID = ((Get-WmiObject Win32_PNPSignedDriver | where {($_.Devicename -eq "$GPUNAME")}).hardwareid).split('\')[1]
$DevicePathName = ($PartitionableGPUList | Where-Object name -like "*$deviceid*").Name
Add-VMGpuPartitionAdapter -VMName $VMName -InstancePath $DevicePathName
}
[float]$devider = [math]::round($(100 / $GPUResourceAllocationPercentage),2)
Set-VMGpuPartitionAdapter -VMName $VMName -MinPartitionVRAM ([math]::round($(1000000000 / $devider))) -MaxPartitionVRAM ([math]::round($(1000000000 / $devider))) -OptimalPartitionVRAM ([math]::round($(1000000000 / $devider)))
Set-VMGPUPartitionAdapter -VMName $VMName -MinPartitionEncode ([math]::round($(18446744073709551615 / $devider))) -MaxPartitionEncode ([math]::round($(18446744073709551615 / $devider))) -OptimalPartitionEncode ([math]::round($(18446744073709551615 / $devider)))
Set-VMGpuPartitionAdapter -VMName $VMName -MinPartitionDecode ([math]::round($(1000000000 / $devider))) -MaxPartitionDecode ([math]::round($(1000000000 / $devider))) -OptimalPartitionDecode ([math]::round($(1000000000 / $devider)))
Set-VMGpuPartitionAdapter -VMName $VMName -MinPartitionCompute ([math]::round($(1000000000 / $devider))) -MaxPartitionCompute ([math]::round($(1000000000 / $devider))) -OptimalPartitionCompute ([math]::round($(1000000000 / $devider)))
}
Assign-VMGPUPartitionAdapter -GPUName AUTO -VMName gamevm -GPUResourceAllocationPercentage 50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment