Hyper-V. Part 1: Creating the first virtual machine
All parts of the series “Hyper-V”Hyper-V is a hypervisor included in every edition of Windows Server: the role is installed with a single command, it needs no separate license, and it can be managed entirely from PowerShell. In this part we take the shortest path from a clean server to a virtual machine with an installed operating system. Theory is kept to a minimum here: each command does exactly what the first machine needs, and what lies behind it and what options it has we will cover in the following parts.
The examples were put together on Windows Server 2025. All commands are run in PowerShell started as administrator, on the future host itself.
What you need
- A server with Windows Server 2025 of any edition — a physical one, because Hyper-V needs direct access to the processor. 8 GB of memory and 100 GB of free space on a separate volume (
D:in the examples) are enough. - Hardware virtualization enabled in the server's BIOS/UEFI — the option is usually called Intel VT-x, Intel Virtualization Technology or AMD-V/SVM.
- An ISO image of the system you are going to install in the machine, for example
D:\ISO\windows-server-2025.iso. - Access to the server console or via RDP. Along the way the server's network will drop for a few seconds, and that is easier to handle from the console.
Checking the processor
Whether the processor is ready can be seen even before the role is installed: systeminfo shows a "Hyper-V Requirements" section at the end of its output.
systeminfo | Select-String 'Hyper-V|Virtualization|Second Level|Data Execution'
All four lines must end in Yes. If it says Virtualization Enabled In Firmware: No, virtualization is disabled in the BIOS: enable it and restart the server. If instead of four lines there is one — "A hypervisor has been detected" — a hypervisor is already running: the role is installed, or this is a virtual machine itself. What exactly is checked and why, we will cover in the part about how Hyper-V is built.
Installing the role
Installation is one command, after which the server restarts (installing the role):
Install-WindowsFeature -Name Hyper-V -IncludeManagementTools -Restart
-IncludeManagementTools adds the Hyper-V PowerShell module and Hyper-V Manager. The restart is needed because after it the server boots on top of the hypervisor. To check that the role is in place:
Get-WindowsFeature -Name Hyper-V*
Get-Service vmms
Moving folders off drive C:
By default Hyper-V puts machine configurations in C:\ProgramData\Microsoft\Windows\Hyper-V, and disks in C:\ProgramData\Microsoft\Windows\Hyper-V\Virtual Hard Disks. A full drive C: will stop both the machines and the host itself, so we move the default paths to a separate volume right away (Set-VMHost):
Set-VMHost -VirtualMachinePath 'D:\Hyper-V' -VirtualHardDiskPath 'D:\Hyper-V\Virtual Hard Disks'
Get-VMHost | Format-List VirtualMachinePath, VirtualHardDiskPath
Creating a switch
For the machine to get on the network, it needs a virtual switch bound to the server's network adapter. First we look up the adapter name:
Get-NetAdapter
Then we create the switch LAN on this adapter (New-VMSwitch):
New-VMSwitch -Name 'LAN' -NetAdapterName 'Ethernet 1' -AllowManagementOS $true
While it runs, the server's network drops for a few seconds: the server's address moves from the physical adapter to the new adapter vEthernet (LAN), through which the server itself is now connected to the switch. If you are connected via RDP, the session will break and reconnect. -AllowManagementOS $true is exactly what keeps the server's access to this network. Why this happens and what other kinds of switches there are — in the part about networking.
Get-VMSwitch
Get-NetIPAddress -AddressFamily IPv4 -InterfaceAlias 'vEthernet (LAN)'
Creating the machine
The machine is created by New-VM, and the rest is configured by the Set-VM* cmdlets (New-VM, step-by-step creation):
$vm = 'app1'
New-VM -Name $vm -Generation 2 -MemoryStartupBytes 4GB `
-NewVHDPath "D:\Hyper-V\Virtual Hard Disks\$vm-os.vhdx" -NewVHDSizeBytes 80GB `
-SwitchName 'LAN' -Path 'D:\Hyper-V'
Set-VMProcessor -VMName $vm -Count 2
Add-VMDvdDrive -VMName $vm -Path 'D:\ISO\windows-server-2025.iso'
Set-VMFirmware -VMName $vm -FirstBootDevice (Get-VMDvdDrive -VMName $vm)
What happens here, briefly:
New-VMcreates a generation 2 machine — a modern one, with UEFI — with 4 GB of memory, a new 80 GB disk and a network adapter connected to the switchLAN. The disk file grows as data is written, so it will not take up 80 GB right away.Set-VMProcessorgives the machine two virtual processors.Add-VMDvdDriveadds a DVD drive and inserts the ISO into it.Set-VMFirmwareputs the DVD first in the boot order — otherwise the machine will try to boot from the empty disk and from the network.
Machine generations and the files a machine consists of we will cover in the part about how Hyper-V is built, disks — in the part about disks, processor and memory — in the part about them.
If you are installing Linux, one more command is needed. Generation 2 machines have Secure Boot enabled, which by default lets only Windows boot loaders through; for Linux we change the template (Set-VMFirmware):
Set-VMFirmware -VMName $vm -SecureBootTemplate MicrosoftUEFICertificateAuthority
Starting the machine and installing the system
Start-VM -Name $vm
vmconnect.exe localhost $vm
vmconnect opens the machine's console window — like a monitor connected to it. The Windows installer on the ISO asks "Press any key to boot from CD or DVD" at boot and waits only a few seconds. If you miss it, the machine will go on to network boot and report that there is no boot device; then restart it — Restart-VM -Name $vm -Force — and immediately press any key in the console window.
What follows is an ordinary system installation, as on a physical server. There is no console window on a Server Core host: there the console is opened from a workstation, which is covered in the part about management from a workstation.
After installation
The image is no longer needed — we eject it so that it does not get in the way of moving the machine to another host later:
Set-VMDvdDrive -VMName $vm -Path $null
To make the machine start by itself after the host restarts, with a one-minute delay:
Set-VM -Name $vm -AutomaticStartAction Start -AutomaticStartDelay 60
The main commands for managing a machine:
Get-VM # list of machines and their state
Stop-VM -Name app1 # shut down the guest gracefully
Start-VM -Name app1
Restart-VM -Name app1 -Force
How Stop-VM, Save-VM and Stop-VM -TurnOff differ, we will cover in the part about how Hyper-V is built.
If you only have Windows 11 at hand
The same commands work on Windows 10 and 11 Pro and Enterprise editions: they include the Hyper-V feature (Hyper-V on Windows). Installation and networking differ:
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All
Restart-Computer
Get-VMSwitch
After installation the workstation already has the switch Default Switch: machines behind it get an address automatically and reach the network through the address of the computer itself. You do not need to create your own switch — specify -SwitchName 'Default Switch' in New-VM, the other commands are the same. This way the first machine can be created on a laptop, without a separate server.
Looking at it by hand
The machine, its state, memory and the address it has received:
Get-VM -Name app1 | Format-List Name, State, Generation, ProcessorCount, MemoryStartup, Uptime, Status
Get-VMNetworkAdapter -VMName app1 | Format-Table Name, SwitchName, MacAddress, IPAddresses
Get-VMHardDiskDrive -VMName app1 | Format-Table ControllerType, Path
IPAddresses is filled in once the system in the machine is installed and has booted: the host learns the address from the guest itself.
Sources
- Install the Hyper-V role on Windows Server — installing the role;
- Install Hyper-V on Windows — Hyper-V on Windows 10 and 11;
- Set-VMHost — default paths;
- New-VMSwitch — creating a switch;
- Create a virtual machine in Hyper-V and New-VM — creating a machine;
- Set-VMFirmware — boot order and Secure Boot template.
We have a host with the Hyper-V role, a switch and a machine with an installed system. Each command in this part is the tip of the iceberg, and the following parts take them apart one by one.
Next — part 2: how Hyper-V is built. What changed in the server after the role was installed, the root and child partitions, VMBus and integration services, machine generations and the configuration version, the machine's files and its states.
Only registered users can leave a comment.
Sign in or register to leave a comment.