Contents

Replace existing NIC of Azure Virtual Machine (ARM) with PowerShell

Contents

Sometimes we just have to do something dumb. For instance, recently I have changed default DNS settings of network adapter on client OS (Windows Server 2016) side of my Azure VM. Next moment, the RDP connection has failed and I couldn’t reconnect again.

The first idea was to replace NIC to another one, which should be recognized by client OS as a new one with default “auto” DNS settings. Well, actually the first idea was to reboot the VM, but it didn’t help.

So let’s see how to replace an existing NIC on Azure VM.

First of all we need to create a new NIC to replace the old one. It can be done with PowerShell, but I used web interface, so let’s assume we already have the replacement NIC.

For some reason I couldn’t replace NIC on existing VM from the Azure Portal. Maybe it’s just as it is, maybe it’s because the VM was not created with multiple NICs in the first place, I’m not sure. I needed a quick fix so I it’s a PowerShell time!

Here is a PowerShell snippet that I used to add a new NIC to VM and remove old one. The script is using Azure RM cmdlets because all my resources were deployed with Resource Manager.

After you replaced NIC you’d want to check if VM can boot normally, than the old interface can be removed or reassigned to another resource. Also you may need to add public IP to the new interface.