This guide walks you through creating a Hyper-V virtual machine on Windows 10 using only PowerShell commands. You’ll learn how to check prerequisites, create a virtual switch, provision a new VM, and install an operating system—all from the command line. No prior PowerShell experience is needed, but basic familiarity with the console helps.
What You’ll Need
- Windows 10 Pro, Enterprise, or Education (Hyper-V is not available on Home edition).
- An ISO file of the operating system you want to install (e.g., Windows 10 ISO).
- Administrator access to run PowerShell as administrator.
- At least 4 GB of RAM and 30 GB of free disk space (more recommended).
- CPU with SLAT (Second Level Address Translation) and virtualization enabled in BIOS/UEFI.
Step-by-Step
- Enable Hyper-V
Open PowerShell as administrator (right-click Start, select “Windows PowerShell (Admin)”). Run:Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All
Restart your PC when prompted. - Verify Hyper-V is active
After reboot, open PowerShell as admin and run:Get-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V
Check that the State is “Enabled”. - Create a virtual switch
To give your VM network access, create an external switch (or internal if you don’t need internet). Run:New-VMSwitch -Name "ExternalSwitch" -NetAdapterName "Ethernet" -AllowManagementOS $true
Replace “Ethernet” with your actual network adapter name (find it viaGet-NetAdapter). - Create a virtual machine
Use the New-VM cmdlet. Example:New-VM -Name "MyVM" -MemoryStartupBytes 2GB -BootDevice VHD -NewVHDPath "D:\VMs\MyVM.vhdx" -NewVHDSizeBytes 40GB -Generation 2 -Switch "ExternalSwitch"
This creates a Gen2 VM with 2 GB RAM and a 40 GB virtual disk. - Configure the VM (optional)
Set the number of virtual processors:Set-VM -Name "MyVM" -ProcessorCount 2
Enable dynamic memory if you want:Set-VMMemory -VMName "MyVM" -DynamicMemoryEnabled $true -MinimumBytes 512MB -MaximumBytes 4GB - Attach the ISO
Mount the OS installation ISO to the VM’s DVD drive:Set-VMDvdDrive -VMName "MyVM" -Path "C:\ISOs\Windows10.iso" - Start the VM
Launch the VM:Start-VM -Name "MyVM" - Connect to the VM console
Open the Hyper-V Manager GUI, or use:vmconnect.exe localhost "MyVM"
Then proceed with the OS installation as usual. - Verify the VM is running
Check status with:Get-VM -Name "MyVM" | Format-List Name, State, CPUUsage, MemoryAssigned
Common Mistakes
- Running PowerShell without admin rights – Most Hyper-V cmdlets require elevation. If you get “Access denied” or “Insufficient privileges”, close and reopen PowerShell as administrator.
- Using the wrong network adapter name – The
-NetAdapterNamemust match your physical adapter exactly. UseGet-NetAdapterto list them. - Creating a Generation 1 VM when you need Gen 2 – Gen 2 supports UEFI and Secure Boot, required for some modern OSes. If you’re installing Windows 10, Gen 2 is recommended.
- Forgetting to enable virtualization in BIOS – Hyper-V won’t start if VT-x/AMD-V is disabled. Check your BIOS settings.
- Not enough disk space – The VHDX file will grow as you use it, but it needs at least the initial size specified. Ensure your host drive has sufficient free space.
Tips
- Use
Get-Help New-VM -Detailedto see all parameters and examples. - Create a dedicated folder for your VM files (e.g.,
D:\VMs) to keep things organized. - Use dynamic memory for development VMs to save host RAM.
- Take a checkpoint (snapshot) before installing updates or testing risky software:
Checkpoint-VM -Name "MyVM" -SnapshotName "BeforeUpdate". - If you plan to use nested virtualization, enable it on the VM with
Set-VMProcessor -VMName "MyVM" -ExposeVirtualizationExtensions $true.
Troubleshooting
Hyper-V feature won’t enable
Run systeminfo and check the Hyper-V requirements section. If it says “A hypervisor has been detected”, you may need to disable other virtualization software (like VMware or VirtualBox) first. Also, ensure your CPU supports SLAT and virtualization is enabled in BIOS.
New-VM fails with “invalid switch”
Make sure the switch name matches exactly. List all switches with Get-VMSwitch. If you haven’t created one, do that first.
VM starts but no display
Check that the ISO is properly attached. Use Get-VMDvdDrive -VMName "MyVM" to verify the path. Also, ensure the VM is set to boot from DVD: Set-VMFirmware -VMName "MyVM" -BootOrder (Get-VMFirmware -VMName "MyVM").BootOrder and make sure the DVD drive is first.
Network not working inside VM
Verify the external switch is bound to the correct physical adapter. Try creating an internal switch and connect the VM to it, then test. Also, check if the host’s firewall is blocking the VM’s traffic.
PowerShell says “Cannot find a drive with the name ‘D:'”
That’s because the path doesn’t exist. Create the directory first: New-Item -ItemType Directory -Path "D:\VMs" or choose an existing path.
VM is paused or stuck
Use Resume-VM -Name "MyVM" to resume. If it’s stuck during shutdown, use Stop-VM -Name "MyVM" -Force to force stop, then start again.
Frequently Asked Questions
Can I use PowerShell to create a VM on Windows 10 Home?
No, Hyper-V is only available on Pro, Enterprise, and Education editions. Home edition doesn’t include the Hyper-V platform.
What’s the difference between Generation 1 and Generation 2 VMs?
Gen 2 uses UEFI firmware and supports features like Secure Boot, TPM, and larger memory. Gen 1 uses legacy BIOS and is compatible with older operating systems like Windows 7.
How do I delete a VM created via PowerShell?
Use Remove-VM -Name "MyVM" -Force to delete the VM configuration. The VHDX file remains; delete it manually if you want to reclaim space.
Can I resize the virtual hard disk after creation?
Yes, use Resize-VHD -Path "D:\VMs\MyVM.vhdx" -SizeBytes 60GB (but the VM must be off). Note that you can only increase the size, not decrease it.
Do I need to install Windows 10 on the VM, or can I use Linux?
You can install any OS that supports the VM generation. For Linux, Gen 2 works with recent distributions (Ubuntu 18.04+). Just attach the appropriate ISO.
How do I enable nested virtualization?
Run Set-VMProcessor -VMName "MyVM" -ExposeVirtualizationExtensions $true on the host, then enable virtualization inside the guest OS. This is useful for running Docker or Hyper-V inside a VM.
Related
General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.
More in this bed
- Gmail Gemini Privacy: Data Access & Limit Settings
- Fix Outlook Inbox Corruption with DISM in Windows
- How to Set Up Apple Pay on iPhone
- How to Choose a Refurbished iPhone With Years of Support
- Voice Dictation in Google Docs: How to Use It
- Turn Off Message Notifications on Mac