PowerShell One-Liner: Create a new Hyper-V VM

My test environment resides on a workstation that runs Windows 8.1 Enterprise Edition with the Hyper-V role enabled. I need to create a new VM that will be used as a second domain controller in my test environment.

I’ll use a PowerShell one-liner to create this new VM which will use a differencing disk based on a Windows Server 2012 R2 vhdx that has been fully patched and syspreped:

New-VM -Name 'DC02' -VHDPath (
New-VHD -Differencing -ParentPath 'D:\Hyper-V\Virtual Hard Disks\template\Server2012R2Core-Template.vhdx' -Path 'D:\Hyper-V\Virtual Hard Disks\dc02.vhdx' -SizeBytes 127GB
).Path -MemoryStartupBytes 512MB -SwitchName 'Internal Virtual Switch' |
Set-VM -ProcessorCount 2 -DynamicMemory -MemoryMinimumBytes 512MB -MemoryMaximumBytes 2GB -Passthru |
Start-VM -Passthru