+2 votes
265 views
How to create Hyper-V PowerShell virtual machine

in Virtualization by (213k points)
reopened | 265 views

1 Answer

+3 votes
Best answer

Virtualization is one of the most common ways we have to test new operating systems, check applications without affecting the physical environment. One of the best known is Hyper-V which is integrated as a feature of Windows 10 and is full of functionalities that allow full interaction between both systems (physical and virtual). One of the traditional ways we create and manage virtual machines is through the Hyper-V graphical interface which seeks to simplify the process, but this time TechnoWikis will explain another mechanism to create a Hyper-V virtual machine and it is through Windows PowerShell which is the integrated management console of Windows 10.

In today's tutorial we can check how easy it is to create Hyper-V virtual machine using only commands through the PowerShell terminal. We can virtualize our team thanks to creating Hyper-V Windows 10 virtual machine without having to use graphic mode. With a couple of commands we will have done the process of creating virtual machine in Windows 10 Hyper-V.

Let's see that it is a simple process, but fully functional to create Hyper-V PowerShell virtual machine.

How to create a Hyper-V PowerShell virtual machine

Step 1

To start the process of creating the virtual machine we must access as administrators Windows PowerShell and there execute the following syntax:
 New-VM -Name "VM Name" -MemoryStartupBytes 6GB -BootDevice VHD -NewVHDPath Route.vhdx -Path "Route" -NewVHDSizeBytes 30GB -Generation 2 -Switch "Adapter" 
VM variables
The variables to be defined are:
  • -New-VM: allows you to create the virtual machine.
  • Name: defines the name of the machine.
  • -MemoryStartupBytes: RAM memory to allocate.
  • BootDevice VHD -NewVHDPath path.vhdx: allows you to create a new virtual hard disk (* .vhdx) in the desired location and set it as a boot device.
  • -Path "Route" -NewVHDSizeBytes 30GB: allows you to define the path where the hard disk will be created and the size to be assigned.
  • Generation 2: defines the generation of the machine to be used (generation 1 or 2).
  • Switch Adapter: allows you to link the network adapter to the virtual machine.
Step 1

Before this we must create the virtual adapter from the option “Virtual Switch Manager” on the Hyper-V platform:

image

Step 2

In our case we will execute the following:
 New-VM -Name Ubuntu19 -MemoryStartupBytes 6GB -BootDevice VHD -NewVHDPath D: \ Hyper-V.vhdx -Path D: \ Hyper-V -NewVHDSizeBytes 30GB -Generation 2 -Switch TechnoWikis 
image
Step 3

We can see that the process has been satisfactory, now we will redirect the ISO image of the desired system to the virtual machine with the following order:
 Add-VMDvdDrive -VMName Ubuntu19 -Path D: \ Software \ Ubuntu \ ubuntu-19.10-desktop-amd64.iso 
Note
The path must be defined where the ISO image is housed.
image
Step 4

Here we have defined:
  • Add-VMDvdDrive: create the virtual DVD drive
  • -VMName: there we enter the machine to associate
  • -Path: Specify the path of the ISO image
Step 5

Now we start the virtual machine with the following command:
 Start-VM -Name Ubuntu19 
Step 6

We connect to it by running:
 VMConnect.exe 
image
Step 7

As a server we will always use "localhost" and in the "Virtual machine" field we can select the desired machine. We click on Accept and this will redirect us to the virtual machine we have created.

In the path we find the associated files:

image

In this way we can create Hyper-V PowerShell virtual machine Windows 10


by (1.4m points)
edited
Please leave a comment if the solution WORKS or NOT.
(with device model) [X]Close

NO NEED REGISTRATION
4,115 questions
4,181 answers
39 comments
2 users