X

How to Create a Hyper-V Virtual Machine using PowerShell

You can create a new VM by using one of the following two methods:

  • Using Windows GUI.
  • Using PowerShell commands.

This article will discuss how to create a Hyper-V virtual machine using PowerShell commands.

Create a Hyper-V Virtual Machine using PowerShell

Step 1. Open PowerShell command with elevated privileges.

Step 2. Execute the following command to create a new VM:

New-VM -Name Testmachine -path C:\vm-machine --MemoryStartupBytes 512MB

If you do not have a directory yet, create it as shown here via PowerShell.

Step 3. Execute the following command to create a new virtual hard disk:

New-VHD -Path c:\vm-Machine\Testmahcine\Testmachine.vhdx -SizeBytes 10GB -Dynamic

Step 4. Execute the following command to attach our new virtual hard disk to the VM:

Add-VMHardDiskDrive -VMName TestMachine -path "C:\vm-machine\Testmachine\Testmachine.vhdx"

Step 5. Execute the following command to map an ISO image to VM CD/DVD (which will be used to install the OS inside the VM, so this can be a Windows or Linux DVD image):

Set-VMDvdDrive -VMName -ControllerNumber 1 -Path

Step 6. Start the new VM:

Start-VM -Name
Karim Buzdar: About the Author: Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various websites.
X

Headline

You can control the ways in which we improve and personalize your experience. Please choose whether you wish to allow the following:

Privacy Settings