HomeMicrosoft Hyper-VHow to Create Hyper-V Virtual Machine with PowerShell

How to Create Hyper-V Virtual Machine with PowerShell

In this article, I cover how to create Hyper-V virtual machine with PowerShell, the Hyper-V cmdlets, and the Hyper-V module. To run the Hyper-V cmdlets in PowerShell referred to in this article, you first need to Enable the Hyper-V Role.

You can create Hyper-V virtual machines using the Hyper-V Manager or PowerShell. In the following steps, we will use a few commands and then create a virtual machine via PowerShell. One of the usual IT administrator’s activities is creating a new virtual machine. We can create a new virtual machine using the PowerShell command or Hyper-V Manager.

I will create a new virtual machine with the below resources. Windows Server 2012, 2 GB of RAM, and 60 GB of disk space.

Create Hyper-V Virtual Machine with PowerShell

Right-click on the Windows Server start button and then open Windows PowerShell with admin rights.

Right click start button Windows

Type the following command to create a new virtual machine with a startup RAM of 2 GB. Press enter

New-VM -Name Server2012 -MemoryStartupBytes 2GB -Path E:\Hyper-V

Note that a new folder is created with the name of the virtual machine (Server2012). So, in this case, Hyper-V will place the virtual machine in E:\Hyper-V.

Create Hyper-V Virtual Machine with PowerShell

Create a Dynamically Expanding Disk

In this step, we will create a new dynamically expanding virtual disk with the extension *.vhdx and a maximum size of 60 GB.
Enter the below command, and then press enter.

New-VHD -Path E:\Hyper-V\Server2012.vhdx -SizeBytes 60GB –Dynamic

Create Hyper-V Virtual Machine

Connect the virtual hard drive to the VM

In this step, we will connect the newly created virtual drive with the virtual machine.
Enter the below command, and then press enter.

Add-VMHardDiskDrive -VMName Server2012 -Path E:\Hyper-V\Server2012.vhdx

Create Hyper-V VM using PowerShell

Connect an ISO file to the Windows installation

Type the following command and then hit enter.

Set-VMDvdDrive -VMName Server2012 -ControllerNumber 1 -Path ‘E:\Servers\Windows Server 2012.iso’

Create Virtual Machine Hyper-V PowerShell

Start the virtual machine

Start-VM –Name Server2012

Start VM PowerShell

View the status of the virtual machine:

Get-VM Server2012

Get VM PowerShell

Conclusion

Of course, there are many other settings you can configure, but this will get you up and running with the virtual machine. Once you get familiar with PowerShell, you will not be going back to creating your virtual machines in the GUI, because this is much faster.
How do you create a Hyper-V virtual machine with PowerShell? Please leave a comment in the comment box.

Refer to Microsoft to learn in detail how to create a Hyper-V virtual machine.

Jamil
Jamilhttp://jamiltech.com
A Professional Technology Blog Writer | An energetic professional with more than 20+ years of rich experience in Technology, Planning, Designing, Installation, and Networking.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments

what is cryptocurrency and bitcoin on How to Backup and Restore IIS Configuration
경기광주출장안마 on How to Backup and Restore IIS Configuration
영등포출장마사지 on How to Backup and Restore IIS Configuration
Twalsu light mirror for vanity on How to Backup and Restore IIS Configuration
fitspresso analysis on How to Reset Microsoft 365 Password
historical landmarks tours for history buffs on How to Add Hyper-V Server Altaro VM Backup
9780443186882 PDF download on How to Migrate Active Directory 2012 to 2022
Shaik Mohammad Jaheer on How to Enable Night Light on Windows 11