From 13355eb3a7024404929e90ee228f001d293a93fa Mon Sep 17 00:00:00 2001 From: Sm0rezDev Date: Mon, 14 Feb 2022 10:33:50 +0100 Subject: [PATCH 1/6] Alter GPU Resource allocation. --- Set-VMGpuPartitionAdapter.ps1 | 47 +++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Set-VMGpuPartitionAdapter.ps1 diff --git a/Set-VMGpuPartitionAdapter.ps1 b/Set-VMGpuPartitionAdapter.ps1 new file mode 100644 index 0000000..a7b2055 --- /dev/null +++ b/Set-VMGpuPartitionAdapter.ps1 @@ -0,0 +1,47 @@ +<# +If you are opening this file in Powershell ISE you should modify the params section like so... +Remember: GPU Name must match the name of the GPU you assigned when creating the VM... + +Param ( +[string]$VMName = "NameofyourVM", +[int]$GPUResourceAllocationPercentage = Precentage(e.g 50 or 25) +) + +#> + +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..." +} \ No newline at end of file From a649b1501b8edc2e0171edc436b119f02c46fb79 Mon Sep 17 00:00:00 2001 From: Sm0rezDev Date: Mon, 14 Feb 2022 10:36:44 +0100 Subject: [PATCH 2/6] Alter GPU resource allocation. --- Set-VMGpuPartitionAdapter.ps1 | 1 - 1 file changed, 1 deletion(-) diff --git a/Set-VMGpuPartitionAdapter.ps1 b/Set-VMGpuPartitionAdapter.ps1 index a7b2055..f21db89 100644 --- a/Set-VMGpuPartitionAdapter.ps1 +++ b/Set-VMGpuPartitionAdapter.ps1 @@ -1,6 +1,5 @@ <# If you are opening this file in Powershell ISE you should modify the params section like so... -Remember: GPU Name must match the name of the GPU you assigned when creating the VM... Param ( [string]$VMName = "NameofyourVM", From 9ca30a9edf66bc031522ce64302df04b128f15f1 Mon Sep 17 00:00:00 2001 From: Sm0rezDev Date: Mon, 14 Feb 2022 11:06:15 +0100 Subject: [PATCH 3/6] Renamed --- Set-VMGpuPartitionAdapter.ps1 => Change-GPUResourceAllocation.ps1 | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Set-VMGpuPartitionAdapter.ps1 => Change-GPUResourceAllocation.ps1 (100%) diff --git a/Set-VMGpuPartitionAdapter.ps1 b/Change-GPUResourceAllocation.ps1 similarity index 100% rename from Set-VMGpuPartitionAdapter.ps1 rename to Change-GPUResourceAllocation.ps1 From 1e1e46f549929eee17b98a3ae93b3275f0343600 Mon Sep 17 00:00:00 2001 From: Sm0rezDev <46298303+Sm0rezDev@users.noreply.github.com> Date: Thu, 3 Nov 2022 10:49:31 +0100 Subject: [PATCH 4/6] Fix: user error Comment inline with param variable --- Change-GPUResourceAllocation.ps1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Change-GPUResourceAllocation.ps1 b/Change-GPUResourceAllocation.ps1 index f21db89..db06f10 100644 --- a/Change-GPUResourceAllocation.ps1 +++ b/Change-GPUResourceAllocation.ps1 @@ -2,8 +2,8 @@ If you are opening this file in Powershell ISE you should modify the params section like so... Param ( -[string]$VMName = "NameofyourVM", -[int]$GPUResourceAllocationPercentage = Precentage(e.g 50 or 25) + [string]$VMName = "NameofyourVM", + [int]$GPUResourceAllocationPercentage = 50 ) #> @@ -11,7 +11,7 @@ Param ( Param ( [string]$VMName, [int]$GPUResourceAllocationPercentage - ) +) $VM = Get-VM -VMName $VMName @@ -43,4 +43,4 @@ if (($VMName -AND $GPUResourceAllocationPercentage) -ne [string]$null) { } "Done..." -} \ No newline at end of file +} From 5ed00b152ce14624507877956dddf9d614b6ccdb Mon Sep 17 00:00:00 2001 From: sm0rezdev Date: Sun, 6 Oct 2024 22:51:13 +0200 Subject: [PATCH 5/6] bcdedit enable debug if flags --- CopyFilesToVM.ps1 | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/CopyFilesToVM.ps1 b/CopyFilesToVM.ps1 index b3aab12..0a1cb90 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" } @@ -454,7 +454,7 @@ function Convert-WindowsImage { [string] [ValidateNotNullOrEmpty()] [ValidateSet("None", "Serial", "1394", "USB", "Local", "Network")] - $EnableDebugger = "None", + $EnableDebugger = "Serial", [Parameter(ParameterSetName="SRC")] [string[]] @@ -4378,6 +4378,9 @@ param( Set-VMHost -ComputerName $ENV:Computername -EnableEnhancedSessionMode $false Set-VMVideo -VMName $VMName -HorizontalResolution 1920 -VerticalResolution 1080 Set-VMKeyProtector -VMName $VMName -NewLocalKeyProtector + if ($EnableDebugger -inotlike "None") { + Set-VMFirmware -VMName $VMName -DisableSecureBoot + } Enable-VMTPM -VMName $VMName Add-VMDvdDrive -VMName $VMName -Path $SourcePath Assign-VMGPUPartitionAdapter -GPUName $GPUName -VMName $VMName -GPUResourceAllocationPercentage $GPUResourceAllocationPercentage From ad196e35061c9c6f0453717e74bf5e90076eefc4 Mon Sep 17 00:00:00 2001 From: sm0rezdev Date: Mon, 7 Oct 2024 00:45:30 +0200 Subject: [PATCH 6/6] revert --- CopyFilesToVM.ps1 | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/CopyFilesToVM.ps1 b/CopyFilesToVM.ps1 index 0a1cb90..4053059 100644 --- a/CopyFilesToVM.ps1 +++ b/CopyFilesToVM.ps1 @@ -454,7 +454,7 @@ function Convert-WindowsImage { [string] [ValidateNotNullOrEmpty()] [ValidateSet("None", "Serial", "1394", "USB", "Local", "Network")] - $EnableDebugger = "Serial", + $EnableDebugger = "None", [Parameter(ParameterSetName="SRC")] [string[]] @@ -4378,9 +4378,6 @@ param( Set-VMHost -ComputerName $ENV:Computername -EnableEnhancedSessionMode $false Set-VMVideo -VMName $VMName -HorizontalResolution 1920 -VerticalResolution 1080 Set-VMKeyProtector -VMName $VMName -NewLocalKeyProtector - if ($EnableDebugger -inotlike "None") { - Set-VMFirmware -VMName $VMName -DisableSecureBoot - } Enable-VMTPM -VMName $VMName Add-VMDvdDrive -VMName $VMName -Path $SourcePath Assign-VMGPUPartitionAdapter -GPUName $GPUName -VMName $VMName -GPUResourceAllocationPercentage $GPUResourceAllocationPercentage