How To: Create a Hyper-V Virtual Machine Using Powershell

If you’re using the free Windows Server 2012 R2 Hyper-V Server download from Microsoft, you will have noticed that the GUI interface is missing. You also may have opted to use the Server Core installation of Windows Server to save resources. Either way, you may want to manage your virtual machines using Powershell. This article will step you through creating a virtual machine using powershell.

In this demonstration, I already have two servers up and running Windows Server 2012 R2 Hyper-V with remote administration enabled.

Logging Into the Server and Creating the Virtual Machine

1. Log into your Hyper-V Host server using Administrative Credentials
2. Locate the CMD window in the background and type Powershell then hit enter

1

3. In the Powershell prompt, you can type Get-Help New-VM -Examples to have the prompt show you some examples of creating a virtual machine.

 Note: If you enter the Get-Help New-VM -Examples command and receive the message “Get-Help cannot find the Help files for this cmdlet on this computer.”, enter the command Update-Help to download the help files automatically.

2

 

Now, I am creating what will be an Active Directory Domain Controller. Here are a few things you will need to know before running the commands that will create the virtual machine:

Name: What you will want to name your VM (YITS-AD1)
NewVHDSizeBytes: The size of the VHD or VHDx you want to create for this virtual machine (60GB)
MemoryStartupBytes: The amount of memory you want to assign to the virtual machine (4096MB)
NewVHDPath: Where you want to store your virtual machine’s VHD file. (C:\Hyper-V\YITS-AD1\Virtual Hard Disks\YITS-AD1-C.VHDx)

 Note: Keep in mind, if your path includes spaces like mine, then you will need to enter it in quotes (You can see the failure in my screenshot below)

4. Using the information above, run the command:

New-VM -Name YITS-AD1 -NewVHDSizeBytes 60GB -MemoryStartupBytes 4096MB -NewVHDPath “C:\Hyper-V\YITS-AD1\Virtual Hard Disks\YITS-AD1-C.vhdx”

3

 

Once your virtual machine is created, now we can either connect to the serve using the Hyper-V Management Console on a remote machine to make additional changes, or we can continue to make changes in Powershell.

4