How to create VM in Hyper-V using PowerShell

Hyper-V virtual machines can be created using the Hyper-V Manager or PowerShell. In this article, we will use a set of commands and create a virtual machine via PowerShell.
Install-VM-via-PowerShell

One of the usual activities as an IT admin is creating a new virtual machine. When it comes to Hyper-V, we can create a new virtual machine using Hyper-V Manager or PowerShell. In this article, we will use a set of commands and create a virtual machine via PowerShell.

I´ll create a virtual machine with the following resources: Windows Server 2019, 16 GB RAM, and 200 GB disk space. The VM will be used to host PRTG Network Monitor.

  1. Left click on the Start Menu and type PowerShell
  2. Right click on the PowerShell and then click Run as administrator
  3. Click Yes to confirm running PowerShell as administrator
  4. Type the command and press Enter.
New-VM -Name PRTGCoreServer -MemoryStartupBytes 16GB -BootDevice VHD -NewVHDPath 
D:\Hyper-V\prtgcore01.vhdx -Path D:\Hyper-V-NewVHDSizeBytes 100GB -Generation 2 -Switch LAN

Commands description:

  • New-VM – create a new virtual machine
  • -Name – the name of the virtual machine. In my example, it is “PRTGCoreServer”
  • -MemoryStartupBytes – the amount of memory
  • -BootDevice VHD -NewVHDPath – location of the virtual disk associated with the virtual machine. In my example “prtgcore01.vhdx” is the name of a virtual disk
  • -Path – the location where we want to store virtual machine
  • NewVHDSizeBytes – the size of a virtual disk
  • -Generation – virtual machine generation. There are two generations available, gen 1 and gen 2.
  • -Switch – virtual switch associated with this virtual machine

5. Mount the ISO file to VM. We´ll use Windows Serve 2019 ISO file downloaded from Microsoft. If you´d like to evaluate the latest Windows edition, please check the Evaluation site.

Add-VMDvdDrive -VMName PRTGCoreServer -Path D:\ISO\WinSrv2019.iso

6. Start the virtual machine.

Start-VM -Name PRTGCoreServer

6. If you navigate to VM’s settings in Hyper-V Manager, you’ll se the exact same configuration.

Thank you for reading this article. In case of any questions, feel free to comment or contact me.

Leave a Reply

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

Share via
Copy link