Renaming Network Interfaces (when you have multiple)
This How-To is for when you have a Hyper-V virtual machine that has multiple network interfaces, and you want/need to rename them to something that’s more relevant to their purpose. For instance, if you are running a virtual firewall, then you’ll at least have two interfaces. One being used for the WAN connection, and the other for a LAN connection. When you add them using the GUI interface, they’ll both be named “Network Adapter” like you see in the two examples below:
With both of them named the same exact thing, it’s very hard to make changes to just one of them in the PowerShell command line (CLI). So in order to rename them, here’s what you need to do.
For reference purposes, the name of our VM in this tutorial is “Test VM” (without the quotes). Please replace all references to “Test VM” with the full name of your VM.
First, you need to open up a PowerShell prompt.
Second, you need to execute the following command to list out the interfaces your VM currently has. (Mostly just so you can see the before and after)
1 |
Get-VMNetworkAdapter -VMName "Test VM" |
This will give you output like this:
1 2 3 4 |
Name IsManagementOs VMName SwitchName MacAddress Status IPAddresses ---- -------------- ------ ---------- ---------- ------ ----------- Network Adapter False Test VM 000000000000 {} Network Adapter False Test VM 000000000000 {} |
Again, you can see both interfaces are named the exact same thing.
Next, you need to execute this:
1 |
$VMNetAdap = Get-VMNetworkAdapter -VMName "Test VM" |
This puts each adapter into an array. Next, you can execute this to see what I mean.
1 |
$VMNetAdap[0] |
And it’ll just return the value of the first entry from above, like so:
1 2 3 |
Name IsManagementOs VMName SwitchName MacAddress Status IPAddresses ---- -------------- ------ ---------- ---------- ------ ----------- Network Adapter False Test VM 000000000000 {} |
Now for the fun part. To rename them, all you now need to do is this:
1 |
Rename-VMNetworkAdapter -VMNetworkAdapter $VMNetAdap[0] -NewName WAN |
1 |
Rename-VMNetworkAdapter -VMNetworkAdapter $VMNetAdap[1] -NewName LAN |
And now you can re-list them on the screen to see the final results:
1 |
Get-VMNetworkAdapter -VMName "Test VM" |
And here’s the results:
1 2 3 4 |
Name IsManagementOs VMName SwitchName MacAddress Status IPAddresses ---- -------------- ------ ---------- ---------- ------ ----------- WAN False Test VM 000000000000 {} LAN False Test VM 000000000000 {} |
And to see it all together in the CLI:
All done!