Run Linux Virtual Machines on Hyper-V: A Comprehensive PowerShell Guide


Hyper-V, a native hypervisor created by Microsoft, allows you to create and run virtual machines (VMs) on a Windows-based system. This guide will take you through the process of setting up and running Linux virtual machines on Hyper-V using PowerShell, providing a comprehensive walkthrough designed for IT professionals and system administrators. By automating the setup with PowerShell, we aim to streamline the process, making it more efficient and less prone to human error.

Setting Up Hyper-V for Linux VMs

Before diving into the PowerShell commands, ensure that Hyper-V is enabled on your Windows machine. You can enable Hyper-V through the Control Panel or by using PowerShell:

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All
New-VMSwitch -Name "PrimaryVirtualSwitch" -SwitchType External -NetAdapterName "YourNetworkAdapterName"

Creating a New Linux VM

To create a new Linux VM, you’ll use the New-VM command. Here’s an example of creating a VM named “UbuntuVM” with 2GB of RAM and a 50GB hard drive:

New-VM -Name UbuntuVM -MemoryStartupBytes 2GB -NewVHDPath "C:\VMs\UbuntuVM.vhdx" -NewVHDSizeBytes 50GB -SwitchName "PrimaryVirtualSwitch"

Installing Linux on the VM

After creating the VM, you need to mount an ISO file containing the Linux distribution you wish to install. Replace “PathToISO” with the actual path to your Linux ISO file:

Set-VMDvdDrive -VMName UbuntuVM -Path "PathToISO"

Next, start the VM and connect to it via the Hyper-V Manager to proceed with the Linux installation:

Start-VM -Name UbuntuVM

Configuring Linux VM with PowerShell

Once Linux is installed, you can configure the VM further using PowerShell commands. For example, to adjust the number of processors, use:

Set-VMProcessor UbuntuVM -Count 2

And to increase the RAM allocation:

Set-VMMemory -VMName UbuntuVM -DynamicMemoryEnabled $true -StartupBytes 4GB

Automation and Scripting


By leveraging PowerShell, IT professionals can efficiently manage and automate the setup and configuration of Linux virtual machines on Hyper-V. This guide provides a foundational understanding, but the versatility of PowerShell allows for customization and scalability in your virtual environment.


Q: Can I run any Linux distribution on Hyper-V? A: Yes, Hyper-V supports various Linux distributions. However, ensure the distribution is compatible with Hyper-V and that you have the correct Linux Integration Services (LIS) version.

Q: How do I access the Linux VM once it’s running? A: You can connect to your Linux VM using Hyper-V Manager or through SSH, depending on how you’ve configured the VM’s network settings.

Q: Can I automate the entire VM setup process with PowerShell? A: Absolutely. PowerShell scripts can be written to automate the entire process of creating, configuring, and managing Linux VMs on Hyper-V, making it an efficient tool for system administrators.

Muhammad Faizan

Hi, My name is Muhammad Faizan and i have spent last 15 years working as System Administrator mainly with Microsoft Technologies. I am MCSE, MCTP, MCITP, certified professional. I love scripting and Powershell is the scripting language i am in love with.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button