PowerShell

How to install Hyper-V and create your first VM with PowerShell (Hyper-Host, Switch, Hyper-V Guest)

Hyper-V is the major competitor to VMWare. In this post I am going to install a Hyper-V host. Afterwards, a guest is put into operation. Everything with PowerShell. Well, what else? 😉

What is an Hyper-V Host what are Hyper-V Guests?

A Hyper-V Host is a computer that runs your virtual machines. The host should be equipped with powerful hardware. RAM and hard disk space are particularly important. You can install Hyper-V on Windows Server 2016 Server Core or on the Desktop Version of Windows Server. There’s also a free standalone Hyper-V Server.

I recommend Server Core or Hyper-V Server. Why? This versions consumes less ressources, are more secure, and have a better performance. You will also have to install fewer updates.

A Hyper-V Guest are the virtual computers which are installed and configured on the Hyper-V Host.  You can run almost every operating system on Hyper-V Guests, even Linux.

Let’s dive in.

Prerequisites

All you need is Windows Server 2012 or 2016. Or Windows 10. Make sure you are running at least Windows 10 professional. In Windows 10 Home Hyper-V is not available.

Installation Hyper-V Host

Windows Server

Open Windows PowerShell with administrative privileges. First of all it’s good to know that there are 3 installation options:


Get-WindowsFeature *Hyper*

Unbenannt.JPG

Hyper-V: The Hypervisor itsself. The software you need to run the Hyper-V host

Hyper-V GUI Management Tools: The graphical user interface for Hyper-V Hosts

Hyper-V Module for Windows PowersShell: The Hyper-V PowerShell Module

For this blog post we need all of them. We can achieve this using the IncludeManagementTools parameter.


Install-WindowsFeature Hyper-V -IncludeManagementTools

Unbenannt.JPG

Fine, that’s it. Check it all out with


virtmgmt.msc

and in PowerShell with


Get-Command -Module Hyper-V

Unbenannt.JPG

Windows 10

For installation on Windows 10 use:


Enable-WindowsOptionalFeature -Online -FeatureName:Microsoft-Hyper-V -All

 

The Hyper-V Switch

Hyper-V Guests usually need a switch to be able to communicate with other VMs or with computers outside the network. Therefore we have to create a virtual Hyper-V Switch.

There are three switch options: Private, Internal and External. Private means that only the virtual computers can communicate with each other. Internal is similar to Private, but VMs can communicate additionally with your host computer running Hyper-V. External connects your virtual machines with the outside network, even with the internet.

External Switch

For this guide, we need an external switch. For the external switch we have to specify a network adapter of our Hyper-V host that will be used by the VM’s to reach hosts outside the network.

Run Get-NetAdapter and memorize the name of your preferred network adapter.


Get-NetAdapter

Now run the following command:


New-VMSwitch -Name Internet -NetAdapterName 'Ethernet' -AllowManagementOS $true

Unbenannt.JPG

Internal Switch

For the sake of form, the configuration of an internal switch.


New-VMSwitch -Name Internal -SwitchType Internal

Unbenannt.JPG

Private Switch


New-VMSwitch -Name Private -SwitchType Private

Unbenannt.JPG

Now we’ve done the most important things. Let’s move on with our first VM Guest.

The first VM

Now we are ready for installing our first virtual computer. Let’s say the computername should be client01 and the memory should be 2 GB. Here we go:


New-VM -Name server01 -MemoryStartupBytes 2GB -SwitchName Internet -Generation 2

Unbenannt.JPG

Let me explain this Generation parameter in more detail. Generation 1 is the old option. Generation 2 the newer option. Using Generation 2 enables you to use UEFI firmware, PXE Boot, SCSI, Secure Boot (only digitally signed bootloader are permitted) and much more. Note that Generation 2 machines must run at least Windows Server 2012 or Windows 8.

Now it’s time to provide an installation medium. I want to install Windows Server 2016. My ISO file is located at C:\Patrick.


Set-VMDvdDrive -VMName server01 -Path C:\Patrick\SW_DVD9_Win_Svr_STD_Core_and_DataCtr_Core_2016_64Bit_German_-3_MLF_X21-30352.ISO

We are almost done. Last but not least let’s start our VM to begin the installation of the operating system.


Start-VM server01

Finally, we want to connect to the VM. In order to do this either open the VM in Hyper-V Manager (right-click – connect) or you can run vmconnect.


vmconnect

1.JPG

Have fun discovering Hyper-V!

Categories: PowerShell

Tagged as: , ,

1 reply »

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.