This blog post will be covering how to create a Hyper-V VM using Powershell.
Create a Hyper-V VM using Powershell
Start by opening an elevated Powershell window.
Enter the command below, replacing the settings for your situation.
New-VM -Name DC -MemoryStartupBytes 512MB -Path D:\ws2012.local
The above command creates a Virtual Machine called DC in D:\ws2012.local with 512 MB memory. 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.
Now we will create a new dynamically expanding Virtual Hard Drive with the new *.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"
Now you might want to connect an *.iso file for the Windows installation:
Set-VMDvdDrive -VMName DC -ControllerNumber 1 -Path "<path to ISO>
Start the VM:
Start-VM –Name DC
View the status of the VM:
I prefer to also set up Dynamic Memory for my machine. In order to do this you first need top 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 🙂