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

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
How to Create a Hyper-V Virtual Machine using PowerShell

One thought on “How to Create a Hyper-V Virtual Machine using PowerShell

  • Permalink

    Hi,
    I am trying to add an existing newly created nano server into Hyper-V using only Powershell.
    I am very new to powershell and could not find an example. I have packages etc installed in Nano so all I need to add it to Hyper-v, give some ram and networking.
    Can you give such an example?

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Ad #native_company# — #native_desc# #native_cta#