How to Install Vagrant with HyperV on Windows

Published on Thursday, 28 June 2018

How to use Vagrant with HyperV on Windows

First thing you need to know about using HyperV on Windows is you need to have at least Windows 10 Aniversary Update or higher. While its possible to run HyerV on earlier versions of windows like Windows 8, this guide makes use of some network features only available in Windows 10.

Also if you enable HyperV it will prevent other hypervisors like VMware and VirtualBox from working too.

Installing Hyper V

To install Hyper V it is as simple as opening an Elevated PowerShell window and running the following command:

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

Setting UP Virtual Networks

To use Vagrant with Hyper V you need to setup VMSwithces for it to use. The other problem you will run into is HyperV doesn't have DHCP out of the box either.

So to work around this we will setup a NAT VMSwitch and we will install a small DHCP service on your host which will do DHCP for it.

Run the following commands from an Elevated PowerShell prompt.

New-VMSwitch -SwitchName "NAT" -SwitchType Internal
New-NetIPAddress -IPAddress -PrefixLength 24 -InterfaceAlias "vEthernet (NAT)"
New-NetNat -Name NAT -InternalIPInterfaceAddressPrefix

Now you have a Virtual network setup, next step is to get DHCP running on it to assign IP Addreses.

Setting up DHCP

Download the latest version of DHCP Server from and unzip it to where you want to keep it on your hard drive (e.g. c:\tools\dhcpserver).

Open the folder you unzipped and double click on DHCPWiz.exe.

Click Next to progress to next screen.


Select the network card named "vEthernet (NAT)".


Click Next.


Enter the IP pool as - 100

Click Advanced


Enter for the subnet mask.

Click Add under DNS Server.


Enter the IP address of your DNS server. If you are unsure put which is google's DNS.

Then click ok


Now under Gateways select and click Edit.


Enter and press Ok.


Click Ok


Click Next


Click Write Ini File and then Next.


Click Admin and Accept the UAC prompt.


Click Install and then Start when it becomes available.


Click Configure and then Exit.


Click Finish


Now you have DHCP configured and running.

Enable PowerShell Remoting

PowerShell remoting is an important part of interacting with Windows virtual machine in vagrant. For this functionality to work properly run the following commands:

Enable-PSRemoting -Force  -SkipNetworkProfileCheck
Enable-WSManCredSSP -Role Server –Force
Enable-WSManCredSSP -Role Client -DelegateComputer * -Force
Start-service winrm
Set-Item "wsman:\localhost\client\trustedhosts" -Value "*" -Force

Installing Vagrant

Now to install vagrant itself. You can do this by downloading the installer from here or running the following chocolatey command:

choco install vagrant -yes

Close and reopen any powershell windows you have open at this point.

Note: By default vagrant will download large files and store configuration in a folder called .vagrant.d in your user profile. If you want to move this to another location you can do so with the VAGRANT_HOME environment variable.

Set default Provider

Last step is to set the VAGRANT_DEFAULT_PROVIDER to hyperv. Doing this will cause vagrant to use VMware as its default provider. If you don't you might have vagrant try and download virtual box which is not what you want.

Testing Vagrant works

In a blank directory that you want to create your VM in run the following commands:

vagrant init hashicorp/precise
vagrant up
vagrant ssh

You should now have an SSH session into a virtual machine. To clean up use the following command:

vagrant destroy