PowerShell’s Docs PowerShell Hyper-V Management Install Hyper-V with PowerShell

In this first post of my series about managing Hyper-V with PowerShell I will outline how to install Hyper-V Server and the Hyper-V role with PowerShell.
Latest posts by Surender Kumar (see all)

Every administrator who is not new to the virtualization world has heard about Hyper-V. It is a type 1 (or bare metal) hypervisor from Microsoft that allows the user to create and run virtual machines on a server or computer. For those who don't know about type 1 and type 2 hypervisors, let me briefly explain both:

  • Type 1—A type 1 hypervisor acts like a low-footprint operating system and runs directly on top of the host computer's hardware. This is why it is also known as a bare metal or native Common examples of type 1 hypervisors are VMware ESXi, Citrix XenServer, and Microsoft Hyper-V. This type of hypervisor is generally used for production-ready virtualization, such as data centers.
  • Type 2—A type 2 hypervisor runs as a software layer on an operating system, like other computer programs. It is also known as a "hosted" hypervisor. Common examples of type 2 hypervisors are VMware Player, Oracle VirtualBox, and Parallels Desktop. The type 2 hypervisor allows an end user to run virtual machines on a personal computer, so this type of hypervisor is generally used for training, development, and research.

Many admins are still confused as to whether Hyper-V is a type 1 or type 2 hypervisor. Since it appears to be running on top of the operating system itself, most people think it is a type 2 hypervisor, but in reality, it's not. Let me tell you why.

When you install or enable the Hyper-V role or feature on a system, the original operating system is converted into a virtual machine, and a layer of Hyper-V hypervisor is added under it. This is why your system is restarted when you install the Hyper-V role or feature. After restart, the original Windows operating system starts working as a virtual machine on top of the Hyper-V hypervisor. In a nutshell, Hyper-V acts as a type 1 or bare metal hypervisor under the hood.

In this article, I will cover how you can manage Hyper-V completely using PowerShell. There are some tools you can use to manage Hyper-V servers using the GUI, but this guide is for the admins who love doing things with PowerShell rather than using the GUI tools.

Hyper-V is available for both server and client operating systems. In server operating systems (Windows Server 2016, Server 2019, Server 2022), it is available as a server role, and on Windows client operating systems (Windows 10 or Windows 11), it is available as an optional feature. Microsoft likes to differentiate between them as Hyper-V on Server and Hyper-V on Windows. So, from here on in, we'll use the official naming scheme. To install the Hyper-V role or feature, you need to use different PowerShell commands depending upon the operating system type.

Install Hyper-V on a server ^

To install Hyper-V on Server, you can use the following command in an elevated PowerShell session:

Install-WindowsFeature -Name Hyper-V -IncludeAllSubFeature -IncludeManagementTools
Install Hyper V on Server using PowerShell

Install Hyper V on Server using PowerShell

This command installs Hyper-V, including all the features and management tools on the Windows Server operating system. If you are trying to install the role on a remote server, you can specify the server name using the -ComputerName parameter. You can also use the -Restart parameter to restart the server automatically to complete the installation.

Install Hyper-V on Windows ^

To install Hyper-V on Windows, you can use the following command in an elevated PowerShell session:

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-All -All
Install Hyper V on Windows using PowerShell

Install Hyper V on Windows using PowerShell

This command enables the specified optional Hyper-V Windows feature, including all dependencies and management tools. It prompts you to restart the system to complete the installation, where you can type "Y" to reboot straight away or "N" to manually reboot later. To suppress this reboot prompt, use the -NoRestart parameter.

Subscribe to 4sysops newsletter!

In my next article I will explain how to create a virtual Hyper-V switch with PowerShell.

Discussion (2)

  1. First, create VM Hyper-V using a ISO Windows 2016. Then, How-to Install-WindowsFeature and apps (chocolatey) using Remote Powershell, against Virtual Machine (Windows 2016) in Hyper-V (in Windows 10) ?

Leave a Reply

Your email address will not be published.

© 4sysops 2006 - 2022


Please ask IT administration questions in the forums. Any other messages are welcome.


Log in with your credentials


Forgot your details?

Create Account