Search
StarWind is a hyperconverged (HCI) vendor with focus on Enterprise ROBO, SMB & Edge

Rename VM network adapter automatically from Virtual Machine Manager 2016

  • May 16, 2016
  • 6 min read
IT and Virtualization Consultant. Romain is specializing in Microsoft technologies such as Hyper-V, System Center, storage, networking, and MS Azure. He is a Microsoft MVP and MCSE in Server Infrastructure and Private Cloud.
IT and Virtualization Consultant. Romain is specializing in Microsoft technologies such as Hyper-V, System Center, storage, networking, and MS Azure. He is a Microsoft MVP and MCSE in Server Infrastructure and Private Cloud.

The next version of Hyper-V which comes with Windows Server 2016, brings a new feature called Virtual Network Adapter Identification. This feature enables to specify a name when a network adapter is added to the virtual machine and to retrieve this same name inside the VM. This feature can be also managed from Virtual Machine Manager 2016. This feature is really great to automate the renaming of the virtual network adapters inside VMs. In this topic I’ll show you how it is working and how to automate the renaming of the network adapters with PowerShell.

harware configure

Set Virtual Network Adapter Identification from VMM

When you create a virtual machine from VMM, you have a new setting in the network adapter configuration called Device Properties. You can set the adapter name as the VM Network name or you can specify your own adapter name. In the below example, I have set LAN as adapter name.

1

When you specify above settings, these settings is enabled from Hyper-V Console perspective :

2

Once the VM is deployed, you can retrieve the custom adapter name by using Get-NetAdapterAdvancedProperty PowerShell cmdlet.

3

As you can see in the above screenshot, you can retrieve the custom adapter name in the Hyper-V Network Adapter Name property. So I make a filter on this property by using a pipe.

4

Then I display only the network adapter name and the custom adapter name. Now we have all the required information to use the Rename-NetAdapter cmdlet.

5

So I have written a PowerShell script to rename automatically the network adapter name by the Virtual Network Adapter Identification :

When this script is executed, the network adapter name is well renamed.

6

Rename the VM’s Network Adapter automatically during deployment

To rename the VM’s network adapter during deployment, I add the above script to the sysprep’d image. So first I mount the VHDX as below.

7

Then I create a folder called Scripts and I paste the script inside the folder. After that I unmount the VHDX.

8

Next I come back to VMM and I edit my VM template. In OS Configuration I add a GUIRunOnce command to run the RenameNetAdapter.ps1 script.

9

Next I deploy a new VM. I specify a custom adapter name as below.

10

Then I add a second network adapter called Cluster. I specify also a custom network adapter.

11

When the VM is deployed and when you are logged once, the RenameNetAdapter script is executed. So the network adapter should be renamed as below.

12

Thanks to the next version of Hyper-V and VMM, we can now automate the VM’s network adapters renaming easily 🙂 .

 

Found Romain’s article helpful? Looking for a reliable, high-performance, and cost-effective shared storage solution for your production cluster?
Dmytro Malynka
Dmytro Malynka StarWind Virtual SAN Product Manager
We’ve got you covered! StarWind Virtual SAN (VSAN) is specifically designed to provide highly-available shared storage for Hyper-V, vSphere, and KVM clusters. With StarWind VSAN, simplicity is key: utilize the local disks of your hypervisor hosts and create shared HA storage for your VMs. Interested in learning more? Book a short StarWind VSAN demo now and see it in action!