From abdbd8f38b05ad8e778f49dde0dbe75c9d15cebc Mon Sep 17 00:00:00 2001 From: Carterpersall Date: Sun, 24 Apr 2022 08:34:03 -0500 Subject: [PATCH] Make scripts prompt for input HyperV Tools\vm-gpusplit.ps1: - Added prompt to enter VM name - Added reference to the MS doc for Set-VM HyperV Tools\vm-setresolution.ps1: - Added prompts for VM name, and VM resolution --- HyperV Tools/vm-gpusplit.ps1 | 11 ++++++++-- HyperV Tools/vm-setresolution.ps1 | 34 ++++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/HyperV Tools/vm-gpusplit.ps1 b/HyperV Tools/vm-gpusplit.ps1 index 82118449..3e0aaac1 100644 --- a/HyperV Tools/vm-gpusplit.ps1 +++ b/HyperV Tools/vm-gpusplit.ps1 @@ -1,4 +1,11 @@ -$vm = "Windows GPU" +while($true){ + $vm = Read-Host 'Please enter the VM name' + if(Get-VM $vm -ErrorAction SilentlyContinue){ #Checks if entered VM exists + break #Breaks the loop if the VM exists + }else{ + Write-Host 'Entered VM does not exist' + } +} Remove-VMGpuPartitionAdapter -VMName $vm Add-VMGpuPartitionAdapter -VMName $vm Set-VMGpuPartitionAdapter -VMName $vm -MinPartitionVRAM 1 @@ -13,7 +20,7 @@ Set-VMGpuPartitionAdapter -VMName $vm -OptimalPartitionDecode 10 Set-VMGpuPartitionAdapter -VMName $vm -MinPartitionCompute 1 Set-VMGpuPartitionAdapter -VMName $vm -MaxPartitionCompute 11 Set-VMGpuPartitionAdapter -VMName $vm -OptimalPartitionCompute 10 -Set-VM -GuestControlledCacheTypes $true -VMName $vm +Set-VM -GuestControlledCacheTypes $true -VMName $vm #See https://docs.microsoft.com/en-us/windows-server/virtualization/hyper-v/deploy/deploying-graphics-devices-using-dda Set-VM -LowMemoryMappedIoSpace 1Gb -VMName $vm Set-VM -HighMemoryMappedIoSpace 32GB -VMName $vm Start-VM -Name $vm \ No newline at end of file diff --git a/HyperV Tools/vm-setresolution.ps1 b/HyperV Tools/vm-setresolution.ps1 index e68e86c0..50b29d8c 100644 --- a/HyperV Tools/vm-setresolution.ps1 +++ b/HyperV Tools/vm-setresolution.ps1 @@ -1 +1,33 @@ -Set-VMVideo -VMName 'Ubuntu 20.04' -HorizontalResolution 2560 -VerticalResolution 1440 -ResolutionType Single \ No newline at end of file +while($true){ + $vm = Read-Host 'Please enter the VM name' + if(Get-VM $vm -ErrorAction SilentlyContinue){ #Checks if entered VM exists + while($true){ + $horizontal = Read-Host 'Please enter the new horizontal resolution of the VM' + Try { + $Null = [convert]::ToInt32($horizontal) #Attempts to convert the input to an integer + $isString = $False + }Catch{$isString = $True} #If the input is not an integer, an error is thrown and $isString is set to true + if($isString){ + Write-Host 'Please enter a valid number' + }else{ + break #Breaks the inner loop if the input is an integer + } + } + while($true){ + $vertical = Read-Host 'Please enter the new vertical resolution of the VM' + Try { + $Null = [convert]::ToInt32($vertical) #Attempts to convert the input to an integer + $isString = $False + }Catch{$isString = $True} #If the input is not an integer, an error is thrown and $isString is set to true + if($isString){ + Write-Host 'Please enter a valid number' + }else{ + break #Breaks the inner loop if the input is an integer + } + } + break #Breaks the outer loop if the VM exists + }else{ + Write-Host 'The VM you entered does not exist' + } +} +Set-VMVideo -VMName $vm -HorizontalResolution $horizontal -VerticalResolution $vertical -ResolutionType Single #Sets the resolution of the VM to the entered values \ No newline at end of file