This blog post will be covering how to create a Hyper-V VM using Powershell.

From the CMD, type Powershell to get in to the Powershell prompt.

New-VM -Name DC -MemoryStartupBytes 512MB -Path D:\ws2012.local

This will create a Virtual Machine called DC in D:\ws2012.local with 512 MB memory. Note that a subfolder will be created with the name of the Virtual Machine. So in my case, the Virtual Machine will be placed in D:\ws2012.local\DC .

Create Virtual Machine Powershell Windows Server 2012

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.local\DC\DC.vhdx -SizeBytes 60GB -Dynamic
New Virtual Hard Drive VHDX Powershell Windows Server 2012

The next step is to connect the newly created Virtual Hard Drive with the Virtual Machine.

Add-VMHardDiskDrive -VMName DC -Path D:\ws2012.local\DC\DC.vhdx" 

Now you might want to connect an *.iso file for the Windows installation:

Set-VMDvdDrive -VMName DC -ControllerNumber 1 -Path "<path to ISO>
Connect DVD Iso Virtual Machine Powershell Windows Server 2012 Hyper-V

Start the VM:

Start-VM –Name DC

View the status of the VM:

Start Virtual Machine Powershell Windows Server 2012 Hyper-V

I prefer to also set up Dynamic Memory for my machine. In order to do this you first need top the machine using:

Stop-VM DC

Then run:

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 🙂