IP Address in VMM with Hyper-V Network Virtualisation

If you are using HNV for your VMs, you may run into the following error when connecting a VM to a VM network:

Error (15020)
The virtual network adapter <VM name> doesn't have a CA (customer address) assigned from the VMSubnet related IP Pool
Recommended Action
Please assign a CA address from the VMSubnet Address Pool to the virtual network adapter and try again

This error message appears because VMM needs to pre-allocate IP addresses for VMs using HNV in order to ensure that the HNV routing tables are updated correctly.

To allocate an IP address from the pool, run the following PowerShell commands (credit to Kristian Nese):

$vm = Get-SCVirtualMachine -Name VM-01"
$pool = Get-SCStaticIPAddressPool -Name "IPPool"
$ip = “192.168.0.10”
Grant-SCIPAddress -GrantToObjectType "VirtualNetworkAdapter" -GrantToObjectID $vm.VirtualNetworkAdapters[0].ID -StaticIPAddressPool $staticIPPool –IPAddress $ip

Once this IP has been granted from the pool, it can be assigned to the corresponding vNIC using the following command:

Set-SCVirtualNetworkAdapter -VirtualNetworkAdapter $vm.VirtualNetworkAdapters[0] -IPv4AddressType static IPv4Addresses $ip