2021-10-11 22:05:04 +00:00
Function New-GPUEnabledVM {
2021-06-23 12:53:19 +00:00
param (
[ int64 ] $HDDSize = 40 GB ,
[ string ] $VMName = " GPU-P " ,
[ int64 ] $MemoryAmount = 8 GB ,
[ int ] $CPUCores = 4 ,
2021-10-11 22:05:04 +00:00
[ string ] $WindowsISOPath = " C:\Users\james\Downloads\Windows11_InsiderPreview_Client_x64_en-us__22000.iso "
2021-06-23 12:53:19 +00:00
)
New-vhd -SizeBytes $HDDSize -Path " C:\Users\Public\Documents\Hyper-V\Virtual hard disks\ $VMName .vhdx " -Dynamic
New-VM -Name $VMName -MemoryStartupBytes $MemoryAmount -VHDPath " C:\Users\Public\Documents\Hyper-V\Virtual hard disks\ $VMName .vhdx " -Generation 2 -SwitchName " Default Switch "
2021-06-23 15:15:23 +00:00
Set-VM -Name $VMName -ProcessorCount $CPUCores -CheckpointType Disabled -LowMemoryMappedIoSpace 3 GB -HighMemoryMappedIoSpace 32 GB -GuestControlledCacheTypes $true -AutomaticStopAction ShutDown
2021-06-23 12:53:19 +00:00
Set-VMMemory -VMName $VMName -DynamicMemoryEnabled $false
2021-06-23 15:15:23 +00:00
Add-VMDvdDrive -VMName $VMName -Path $WindowsISOPath
Set-VMFirmware -VMName $VMName -BootOrder $ ( ( Get-VMFirmware -VMName " GPU-P " ) . BootOrder . Device | Where-Object name -like " DVD* " ) , $ ( ( Get-VMFirmware -VMName " GPU-P " ) . BootOrder . Device | Where-Object name -like " Hard Drive* " ) , $ ( ( Get-VMFirmware -VMName " GPU-P " ) . BootOrder . Device | Where-Object name -like " Network Adapter* " )
2021-06-23 12:53:19 +00:00
}
Function Get-VMGpuPartitionAdapterFriendlyName {
$Devices = ( Get-VMHostPartitionableGpu ) . Name
Foreach ( $GPU in $Devices ) {
$GPUParse = $GPU . Split ( '#' ) [ 1 ]
Get-WmiObject Win32_PNPSignedDriver | where { ( $_ . HardwareID -eq " PCI\ $GPUParse " ) } | select DeviceName -ExpandProperty DeviceName
}
}
2021-06-23 13:54:32 +00:00
2021-06-23 12:53:19 +00:00
function Assign-VMGPUPartitionAdapter {
param (
[ string ] $VMName ,
[ string ] $GPUName
)
$DeviceID = ( ( Get-WmiObject Win32_PNPSignedDriver | where { ( $_ . Devicename -eq " $GPUNAME " ) } ) . hardwareid ) . split ( '\' ) [ 1 ]
$DevicePathName = ( Get-VMHostPartitionableGpu | Where-Object name -like " * $deviceid * " ) . Name
Add-VMGpuPartitionAdapter -VMName $VMName -InstancePath $DevicePathName
2021-06-23 13:54:32 +00:00
Set-VMGpuPartitionAdapter -VMName $VMName -MinPartitionVRAM 0 -MaxPartitionVRAM 1000000000 -OptimalPartitionVRAM 1000000000
Set-VMGPUPartitionAdapter -VMName $VMName -MinPartitionEncode 0 -MaxPartitionEncode 18446744073709551615 -OptimalPartitionEncode 18446744073709551615
Set-VMGpuPartitionAdapter -VMName $VMName -MinPartitionDecode 0 -MaxPartitionDecode 1000000000 -OptimalPartitionDecode 1000000000
Set-VMGpuPartitionAdapter -VMName $VMName -MinPartitionCompute 0 -MaxPartitionCompute 1000000000 -OptimalPartitionCompute 1000000000
2021-06-23 12:53:19 +00:00
}
2021-10-11 22:05:04 +00:00
Assign-VMGPUPartitionAdapter -GPUName " NVIDIA GeForce RTX 2060 SUPER " -VMName " GPU-P "
2021-06-23 12:53:19 +00:00