How to Use Hyper-V
Hyper-V in Windows 10 Pro
This option is only applicable to Windows 10 Pro
How to activate it?
Enable Hyper-V on Windows 10. Go to Control Panel → Programs → Turn Windowsfeatures on or off, check Hyper-V option, make sure all components are selected, and click OK. You may reboot your computer once the Hyper-V feature was added.
Manually Install the Hyper-V role
-
Right click on the Windows button and select ‘Programs and Features’.
-
Select Turn Windows Features on or off.
-
Select Hyper-V and click OK.
When the installation has completed you are prompted to restart your computer.
Install Hyper-V with PowerShell
-
Open a PowerShell console as Administrator.
-
Run the following command:
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V –All
When the installation has completed you need to reboot the computer.
Install Hyper-V with DISM
The Deployment Image Servicing and Management tool or DISM is used to service Windows images and prepare Windows Pre installation environments. DISM can also be used to enable Windows features while the operating system is running. For more information, see DISM Technical Reference.
To enable the Hyper-V role using DISM:
-
Open up a PowerShell or CMD session as Administrator.
-
Type the following command:
DISM /Online /Enable-Feature /All /FeatureName:Microsoft-Hyper-V
Next Step - Create a Virtual Switch
Create a Virtual Switch
Sarah Cooley|Last Updated: 11/12/2015
|
1 Contributor
Before you create a virtual machine in Hyper-V you need to provide a way for this virtual machine to connect to a physical network. Hyper-V includes software based networking technology that allows a virtual machines network card to connect to a virtual switch, providing network connectivity. Each virtual switch created in Hyper-V can be configured with one of three connection types:
-
External Network – the virtual switch is connected to a physical network adapted which provides connectivity between the physical network, the Hyper-V host, and the virtual machine. In this configuration you can also enable or disable the hosts ability to communicate over the physically connected network card. This can be useful to isolate only VM traffic to a particular physical network card.
-
Internal Network – the virtual switch is not connected to a physical network adapter, however network connectivity exists between virtual machines and Hyper-V host.
-
Private Network – the virtual switch is not connected to a physical network adapter and connectivity does not exist between virtual machines and Hyper-V host.
Manually Create a Virtual Switch
This exercise walks through how to create an external virtual switch using the Hyper-V management Manager. When completed your Hyper-V host contains a virtual switch that can be used to connect virtual machines to a physical network.
-
Open up Hyper-V Manager.
-
Right Click on the name of the Hyper-V host and select Virtual Switch Manager.
-
Under ‘Virtual Switches’ select new virtual network switch.
-
Under ‘Create virtual switch’ select External.
-
Select the Create Virtual Switch button.
-
Under ‘Virtual Switch Properties’ give the new switch a name such as External VM Switch.
-
Under ‘Connection Type’ ensure that External Network has been selected.
-
Select the physical network card that to be paired with the new virtual switch, this is the network card that is physically connected to the network.
-
Select Apply to create the virtual switch. At this point you will most likely see the following message, click Yes to continue.
-
Select OK to close the Virtual Switch Manager Window.
Create a Virtual Switch with PowerShell
The following steps can be used to create a virtual switch with an external connection using PowerShell.
-
Use Get-NetAdapter to return a list of network adapters connected to the Windows 10 system.
-
PS C:\> Get-NetAdapter Name InterfaceDescription ifIndex Status MacAddress LinkSpeed ---- -------------------- ------- ------ ---------- --------- Ethernet 2 Broadcom NetXtreme 57xx Gigabit Cont... 5 Up BC-30-5B-A8-C1-7F 1 Gbps Ethernet Intel(R) PRO/100 M Desktop Adapter 3 Up 00-0E-0C-A8-DC-31 10 Mbps
-
Select the network adapter to use with the Hyper-V switch and place an instance in a variable named $net.
-
$net = Get-NetAdapter -Name 'Ethernet'
-
Execute the following command to create the new Hyper-V virtual switch.
-
New-VMSwitch -Name "External VM Switch" -AllowManagementOS $True -NetAdapterName $net.Name
Virtual Switches and Laptops
If running Windows 10 Hyper-V on a laptop you may want to create a virtual switch for both the ethernet and wireless network cards. With this configuration you can change your virtual machines between theses switches dependent on how the laptop is network connected. Virtual machines will not automatically switch between wired and wireless.
Next Step - Create a Virtual Machine
Deploy a Windows Virtual Machine in Hyper-V on Windows 10
Sarah Cooley|Last Updated: 12/11/2015
|
1 Contributor
You can create a virtual machine and deploy an operating system to it in many different ways, for example using Windows Deployment Services, attaching a prepared virtual hard drive, or manually using the installation media. This article walks through how to create a virtual machine and deploy an operating system to the virtual machine using the operating system installation media.
Before starting this exercise, you need an .iso file for the operating system that you would like to deploy. If needed, grab an evaluation copy of Windows 8.1 or Windows 10 from the TechNet Evaluation Center.
Create a Virtual Machine with Hyper-V Manager
These steps walk through how to manually create a virtual machine and deploy an operating system to this virtual machine.
-
In Hyper-V Manager click Action > New > Virtual Machine.
-
Review the ‘Before You Begin’ content and click Next.
-
Give the Virtual Machine a name. Note, this is the name of the Virtual Machine and not the computer name given to the system once the operating system has been deployed.
-
Chose a location where the virtual machine files will be stored such as c:\virtualmachine. You can also accept the default location. Click Next when done.
-
Select a generation for the machine and click Next.
-
Generation 2 virtual machines were introduced with Windows Server 2012 R2 and provide a simplified virtual hardware model and some additional functionality. You can only install a 64-bit operating system on a generation 2 virtual machine. For more information on Generation 2 virtual machines see the Generation 2 Virtual Machine Overview.
-
Select 2048 for the Startup Memory value and leave Use Dynamic Memory, selected. Click the Next button.
-
Memory is shared between a Hyper-V host and the virtual machine running on the host. The number of virtual machine’s that can run on a single host is in part dependent on available memory. A virtual machine can also be configured to use Dynamic Memory. When enabled, dynamic memory reclaims unused memory from the running virtual machine. This allows more virtual machines to run on the host. For more information on Dynamic Memory, see the Hyper-V Dynamic Memory Overview.
-
On the Configure Networking wizard, select a virtual switch for the virtual machine and click Next. For more information, see Create a Virtual Switch.
-
Give the virtual hard drive a name, select a location or keep the default, and finally specify a size. Click Next when ready.
-
A virtual hard drive provides storage for a virtual machine similar to a physical hard drive. A virtual hard drive is required so that you can install an operating system on the virtual machine.
-
On the Installation Options wizard, select Install an operating system from a bootable image file and then select an operating system .iso file. Click Next once completed.
-
When creating a virtual machine, you can configure some operating system installation options. The three options available are:
-
Install an operating system later – this option makes no additional modification to the virtual machine.
-
Install an operating system from a bootable image file – this is similar to inserting a cd into the physical CD Rom drive of a physical computer. To configure this option, select a .iso image. This image will be mounted to the virtual CD Rom drive of the virtual machine. The boot order of the virtual machine is changed to boot first from the CD Rom drive.
-
Install an operating system from a network-based installation server – This option is not be available unless you have connected the virtual machine to a network switch. In this configuration the virtual machine attempts to boot from the network.
-
Review the virtual machine details and click Finish to complete the virtual machine creation.
Create a Virtual Machine with PowerShell
-
Open up the PowerShell ISE as Administrator.
-
Run the following script. This script
-
# Set VM Name, Switch Name, and Installation Media Path. $VMName = 'TESTVM' $Switch = 'External VM Switch' $InstallMedia = 'C:\Users\Administrator\Desktop\en_windows_10_enterprise_x64_dvd_6851151.iso' # Create New Virtual Machine New-VM -Name $VMName -MemoryStartupBytes 2147483648 -Generation 2 -NewVHDPath "D:\Virtual Machines\$VMName\$VMName.vhdx" -NewVHDSizeBytes 53687091200 -Path "D:\Virtual Machines\$VMName" -SwitchName $Switch # Add DVD Drive to Virtual Machine Add-VMScsiController -VMName $VMName Add-VMDvdDrive -VMName $VMName -ControllerNumber 1 -ControllerLocation 0 -Path $InstallMedia # Mount Installation Media $DVDDrive = Get-VMDvdDrive -VMName $VMName # Configure Virtual Machine to Boot from DVD Set-VMFirmware -VMName $VMName -FirstBootDevice $DVDDrive
Complete the Operating System Deployment
In order to finish building your virtual machine, you need to start the virtual machine and walk through the operating system installation.
-
In Hyper-V Manager, double-click on the virtual machine. This launches the VMConnect tool.
-
In VMConnect, click on the green Start button. This is like pressing the power button on a physical computer. You may be prompted to ‘Press any key to boot from CD or DVD’, go ahead and do so.
-
The virtual machine boots into setup and you can walk through the installation like you would on a physical computer.
Note: Unless you're running a volume licensed version of Windows, you need a seperate license for Windows running inside a virtual machine. The virtual machine's operating system is independent of the host operating system.
Next Step - Virtual Machine Checkpoints
Step 8: Working with Hyper-V and Windows PowerShell
Sarah Cooley|Last Updated: 11/12/2015
|
3 Contributors
Now that you have walked through the basics of deploying Hyper-V, creating virtual machines and managing these virtual machines, let’s explore how you can automate many of these activities with PowerShell.
Return a list of Hyper-V commands
-
Click on the Windows start button, type PowerShell.
-
Run the following command to display a searchable list of PowerShell commands available with the Hyper-V PowerShell Module.
-
get-command –module hyper-v | out-gridview
-
You get something like this:
-
To learn more about a particular PowerShell command use get-help. For instance running the following command returns information about the get-vm Hyper-V command.
-
get-help get-vm
-
The output shows you how to structure the command, what the required and optional parameters are, and the aliases that you can use.
Return a list of virtual machines
Use the get-vm command to return a list of virtual machines.
-
In PowerShell, run the following command:
-
get-vm
-
This displays something like this:
-
To return a list of only powered on virtual machines add a filter to the get-vm command. A filter can be added by using the where-object command. For more information on filtering see the Using the Where-Object documentation.
-
get-vm | where {$_.State –eq ‘Running’}
-
To list all virtual machines in a powered off state, run the following command. This command is a copy of the command from step 2 with the filter changed from ‘Running’ to ‘Off’.
-
get-vm | where {$_.State –eq ‘Off’}
Start and shut down virtual machines
-
To start a particular virtual machine, run the following command with name of the virtual machine:
-
Start-vm –Name <virtual machine name>
-
To start all currently powered off virtual machines, get a list of those machines and pipe the list to the 'start-vm' command:
-
get-vm | where {$_.State –eq ‘Off’} | start-vm
-
To shut down all running virtual machines, run this:
-
get-vm | where {$_.State –eq ‘Running’} | stop-vm
Create a VM checkpoint
To create a checkpoint using PowerShell, select the virtual machine using the get-vm command and pipe this to the checkpoint-vmcommand. Finally give the checkpoint a name using -snapshotname. The complete command looks like the following:
get-vm -Name <VM Name> | checkpoint-vm -snapshotname <name for snapshot>
Create a new virtual machine
The following example shows how to create a new virtual machine in the PowerShell Integrated Scripting Environment (ISE). This is a simple example and could be expanded on to include additional PowerShell features and more advanced VM deployments.
-
To open the PowerShell ISE click on start, type PowerShell ISE.
-
Run the following code to create a virtual machine. See the New-VM documentation for detailed information on the New-VM command.
-
$VMName = "VMNAME" $VM = @{ Name = $VMName MemoryStartupBytes = 2147483648 Generation = 2 NewVHDPath = "C:\Virtual Machines\$VMName\$VMName.vhdx" NewVHDSizeBytes = 53687091200 BootDevice = "VHD" Path = "C:\Virtual Machines\$VMName " SwitchName = (get-vmswitch).Name[0] } New-VM @VM
Wrap up and References
This document has shown some simple steps to explorer the Hyper-V PowerShell module as well as some sample scenarios. For more information on the Hyper-V PowerShell module, see the Hyper-V Cmdlets in Windows PowerShell reference.
Prepare your computer
To get your computer prepared to run Hyper-V, make sure that the hardware virtualization support is enabled in the BIOS first. Boot into BIOS on your computer, enable Virtualization Technology under System Security. Depending on the version of BIOS you are running, you may need to poke around to find it.
Enable Hyper-V on Windows 10
Go to Control Panel → Programs → Turn Windows features on or off, check Hyper-V option, make sure all components are selected, and click OK.
You may reboot your computer once the Hyper-V feature was added.
Open Hyper-V Manager
Click Start button, and then All apps, you will see Hyper-V Manage Tools appears under H section. Expand it to find Hyper-V Manager.
I was having a little difficulties finding Hyper-V Manager when I first tried. It’s not in All apps, nor in Search results. What I ended up doing is to add it as an Snap-in component to a blank MMC console.
Click Start button, type in “MMC”, and press Enter. It will open a blank MMC Console. Then go to File → Add/Remove Snap-in, add Hyper-V Manage component from left, and click OK. Pick local computer as the remote server.
Either way, you will have Hyper-V Manager opened up on your computer without any issue.
First thing to do in Hyper-V
The first thing you need to do after you enabled Hyper-V feature is to create a network switch. You will need one to create and run virtual machines.
Open Hyper-V Manager, right-click the host, and choose Virtual Switch Manager. You can also find it on Actions panel as well.
Select one of 3 types of virtual switch, and click Create Virtual Switch button.
-
External – if a virtual machine needs to get access to a physical network directly.
-
Internal – if no need to get access to physical network.
-
Private – if a virtual machine only runs on this host.
You may as well configure Hyper-V settings on this particular host to specify the default folder to store virtual disks and virtual machine configuration files.
Once that’s all done, you can now import an existing VM or create a brand new one to start enjoying running a second OS in Hyper-V on your Windows 10 computer.