Use Automation To Accessibly Install Windows In Hyper-V
This is a guide that will show you how to install Windows in a Hyper-V VM if you're blind. I wanted to write and share this because I'd like everyone who is struggling to do this while blind or visually impaired to have an alternative solution, because Microsoft makes it completely impossible to do. Of course, my alternative suggestion would be to use VMware, because it connects your OS soundcard to the vm so you can hear Narrator when you boot into Windows setup. But, if you're stuck using hyper-v or you just want to use it instead, here you go. You can follow this guide and you won't even have to touch a virtual gui.
Also, I originally wrote this guide as a proof of concept for some accessibility work I was doing, but those guys haven't done anything with it so far as I'm aware so I'm posting it here.
Preparation
Before you begin, you will need to gather and prepare a few things. Complete the following:
- Obtain a copy of the Hyper-V Automation PowerShell Scripts
- Obtain a copy of the Windows operating system you want to install in ISO format (this guide demonstrates with Windows Server 2022)
- Create a directory and place the scripts and the image into it.
- Open Hyper-V Manager and right-click/applications keypress, the name of your system in the treeview. Select Virtual Switch Manager.
- On the "New Virtual Network Switch" menu item, tab and select "External Switch" as the type of switch to create. Press the "Create Virtual Switch" button.
- Find the "New Virtual Network Switch" in the menu, and tab to the Name edit box. Call this "SWITCH". This is not a crucial step, as you can name the switch anything you want. You would just have to specify it when running the script, but "SWITCH" is the default name. Press the "OK" button.
- Right-Click your machine's name again, but this time select "Hyper-V Settings". Scroll down to "Enhanced Session Mode Policy" and tab to the "Allow enhanced session mode" checkbox. Check it, and press the "OK" button. Now, you're ready to jump into PowerShell.
Automating VM Creation
To get started, search for PowerShell in the start menu, right-click and select "Run As Administrator". Change directory to the one you stored your scripts and ISO in, and run this command.
Set-ExecutionPolicy Bypass
This turns off PowerShell's defenses against unsighed scripts that may be harmful to you.
Now, you can create a VM. Run this command, substituting values as necessary.
./New-VMFromWindowsImage.ps1 -SourcePath "isoFilename" -Edition "2" -VMName "name" -VHDXSizeBytes xGB -AdministratorPassword "supersecurepassword" -Version "version" -MemoryStartupBytes xGB -VMProcessorCount 1
The following is a list of the arguments and what they do:
- -SourcePath: the path to the Windows ISO file
- -Edition: the edition of windows to install. You can pick a number that corresponds to the actual edition you would see when installing Windows manually. For example, "Server Desktop Experience" is the second option, so we would specify "2"
- -VmName: the name of your VM
- -VHDXSizeBytes: the size of your virtual hard drive. You can give an argument like "60GB" instead of having to spell out the number of bytes. Windows will figure that out for you.
- -AdministratorPassword: the password of the local administrator account on the VM.
- -Version: the specific version of Windows you're installing, such as "Server2022Standard". Valid options are 'Server2022Datacenter', 'Server2022Standard', 'Server2019Datacenter', 'Server2019Standard', 'Server2016Datacenter', 'Server2016Standard', 'Windows10Enterprise', 'Windows10Professional', and 'Windows81Professional'
- -MemoryStartupBytes: the amount of ram to give to the VM. Again, specifying it in GB will work.
- -VMProcessorCount: the amount of processor cores to allocate for your VM.
- For more options and a more detailed explanation, see "readme.md" in the extracted files you obtained from GitHub.
Example command:
./New-VMFromWindowsImage.ps1 -SourcePath "Windows Server2022 Trial.iso" -Edition "2" -VMName "WinServerTest" -VHDXSizeBytes 60000000000 -AdministratorPassword "myTestPassw0rd!" -Version "Server2022Standard" -MemoryStartupBytes 12GB -VMProcessorCount 4
Note: This command may take some time to run. If you see it running itself again, press ctrl+C.
Connecting To the VM
Once your vm has been created, go to Hyper-V Manager to ensure it was created successfully. If it has been, proceed to the below PowerShell instructions.
If you want to use an enhanced session while connected to this VM, it will be necessary to enable Remote Desktop. This is how Hyper-V Manager connects to your VM to share local and remote resources, such as USB drives, audio, and network resources. However, if you are not concerned with those things, the rest of this guide is irrelivant and you may proceed to use the VM normally.
To enable Remote Desktop from PowerShell, Run the following commands, replacing values where necessary.
$remoteConnection = ./New-VMSession.ps1 -VMName "name" -AdministratorPassword "supersecurepassword"
.\Enable-RemoteManagementViaSession.ps1 -Session $remoteConnection
Invoke-Command -Session $remoteConnection {
Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server' -name "fDenyTSConnections" -value 0
Enable-NetFirewallRule -DisplayGroup "Remote Desktop"
}
Any commands other commands you'd like to run remotely on the VM before you access it can be placed inside the braces. Here's an example:
$remoteConnection = ./New-VMSession.ps1 -VMName "WinServerTest" -AdministratorPassword "myTestPassw0rd!"
.\Enable-RemoteManagementViaSession.ps1 -Session $remoteConnection
Invoke-Command -Session $remoteConnection {
Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server' -name "fDenyTSConnections" -value 0
Enable-NetFirewallRule -DisplayGroup "Remote Desktop"
}
Connecting to the VM
Finally, we're ready to connect to the VM. In Hyper-V manager, right-click the VM and select "Connect." You will be prompted to choose some settings before you connect, such as the screen space the VM will occupy, or resources you'd like to share. Once you've set everything the way you want it, press "Connect." Proceed to use the VM as you would a normal computer.
Note: Release your keyboard and mouse from the VM by pressing CTRL+ALT+Left Arrow.