As with most of Microsoft’s products nowadays, you can either use the GUI or use Powershell.
Using Powershell allows you to create Hyper-V virtual machines using templates systematically, and you can also automate the whole process.
In this blog post, I cover how to create Hyper-V virtual machines using Powershell.
How to create a VM using Powershell in Hyper-V
Start by opening an elevated Powershell window.
Enter the command below to create a new virtual machine with a startup RAM memory of 512 GB
New-VM -Name DC -MemoryStartupBytes 512MB -Path D:\ws2012.local
Note that a subfolder is created with the name of the virtual machine. So in my case, the virtual machine will be placed in D:\ws2012.localDC.
The next step is to create a new dynamically expanding Virtual Hard Drive with the *.vhdx file extension and with a maximum size of 60 GB using:
New-VHD -Path D:\ws2012.localDCDC.vhdx -SizeBytes 60GB -Dynamic
The next step is to connect the newly created Virtual Hard Drive with the virtual machine.
Add-VMHardDiskDrive -VMName DC -Path D:\ws2012.localDCDC.vhdx"
Connect a *.iso file for the Windows installation:
Set-VMDvdDrive -VMName DC -ControllerNumber 1 -Path "<path to ISO>
Start the virtual machine:
Start-VM –Name DC
View the status of the virtual machine:
I also prefer to set up dynamic memory for my machine. This means that the virtual machine will only use the memory required.
To accomplish this, you first need to stop the machine using:
Set-VMMemory -VMName DC -DynamicMemoryEnabled $true -StartupBytes 512MB -MinimumByte 512
There are of course a lot more settings you can configure, but this will get you up and running. Once you get the hang of Powershell, you won’t be going back to create your machines in the GUI, as this is much faster and less error-prone 🙂
How do you create virtual machines in Hyper-V? Please leave a comment below!