diff --git a/Change-GPUResourceAllocation.ps1 b/Change-GPUResourceAllocation.ps1 new file mode 100644 index 0000000..db06f10 --- /dev/null +++ b/Change-GPUResourceAllocation.ps1 @@ -0,0 +1,46 @@ +<# +If you are opening this file in Powershell ISE you should modify the params section like so... + +Param ( + [string]$VMName = "NameofyourVM", + [int]$GPUResourceAllocationPercentage = 50 +) + +#> + +Param ( + [string]$VMName, + [int]$GPUResourceAllocationPercentage +) + +$VM = Get-VM -VMName $VMName + +if (($VMName -AND $GPUResourceAllocationPercentage) -ne [string]$null) { + If ($VM.state -eq "Running") { + [bool]$state_was_running = $true + } + + if ($VM.state -ne "Off"){ + "Attemping to shutdown VM..." + Stop-VM -Name $VMName -Force + } + + While ($VM.State -ne "Off") { + Start-Sleep -s 3 + "Waiting for VM to shutdown - make sure there are no unsaved documents..." + } + + [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))) + + If ($state_was_running){ + "Previous State was running so starting VM..." + Start-VM $VMName + } + + "Done..." +} diff --git a/CopyFilesToVM.ps1 b/CopyFilesToVM.ps1 index b3aab12..4053059 100644 --- a/CopyFilesToVM.ps1 +++ b/CopyFilesToVM.ps1 @@ -1,21 +1,21 @@ $params = @{ - VMName = "GPUPV" - SourcePath = "C:\Users\james\Downloads\Win11_English_x64.iso" + VMName = "Win11LABENV" + SourcePath = "E:\Users\simon\Downloads\Win11_23H2_English_x64.iso" Edition = 6 VhdFormat = "VHDX" DiskLayout = "UEFI" - SizeBytes = 40GB + SizeBytes = 128GB MemoryAmount = 8GB - CPUCores = 4 + CPUCores = 6 NetworkSwitch = "Default Switch" - VHDPath = "C:\Users\Public\Documents\Hyper-V\Virtual Hard Disks\" + VHDPath = "D:\Hyper-V\Virtual Hard Disks\" UnattendPath = "$PSScriptRoot"+"\autounattend.xml" - GPUName = "AUTO" + GPUName = "NVIDIA GeForce RTX 2070 SUPER" GPUResourceAllocationPercentage = 50 Team_ID = "" Key = "" - Username = "GPUVM" - Password = "CoolestPassword!" + Username = "LABENV" + Password = "qwerty" Autologon = "true" }