Adding Multiple Network Interfaces to an existing ARM based Virtual machine

At this point, there is no way of adding \ associating additional Network Interfaces via the portal to an existing Virtual machine. We can add additional Network Interfaces during the time we create \ provision a new virtual machine or by deleting the existing virtual machine (keeping the disk) and re-provisioning the Virtual machine using the same OS VHD with associating multiple Network interfaces.

Before we begin, I suggest that you go through following article which to refer the requirements and constraints only.

You can also refer following article which helps describes in details on how to deploy a new virtual machine with multiple network interface in Azure Resource manager

As our goal is to add multiple Network Interface to an existing Virtual Machine we will have to delete the existing virtual machine and then re-create \ re-provision the Virtual Machine using following script

Note: The below script creates a Virtual Machine in an Availability Set and adds 2 network interfaces with one Public and Private IP on the Primary NIC and a Private IP on the secondary NIC.

As this virtual machine is going to be a part of Availability Set, at later stage we can even create an Azure Load balancer and add another Public IP.

Select-AzureRmSubscription -SubscriptionName

###Update the below Environment details #####
$VirtualMachineName = "sushrao1"

## Existing OS VHD of the deleted Virtual Machine ##
$sourceImageUri = ""
$diskName= $VirtualMachineName + "OS-Disk"

$LocationName="east us"
$cred = New-Object PSCredential $adminUsername, ($adminPassword | ConvertTo-SecureString -AsPlainText -Force)

## Get the existing virtual network  ##
$vnet=Get-AzureRMvirtualNetwork -Name $vnetName -ResourceGroupName $ResourceGroupName

## Create the NIC1 ##

$pipName= $VirtualMachineName + "_pip"
$domName= $VirtualMachineName
$pip=New-AzureRmPublicIpAddress -Name $pipName -ResourceGroupName $ResourceGroupName -DomainNameLabel $domName -Location $LocationName -AllocationMethod Dynamic
$nic=New-AzureRmNetworkInterface -Name $nicName -ResourceGroupName $ResourceGroupName -Location $LocationName -SubnetId $vnet.Subnets[$subnetIndex].Id -PublicIpAddressId $pip.Id -PrivateIpAddress $PrivateIPforNIC1

## Create the NIC2 ##

$nic2=New-AzureRmNetworkInterface -Name $nicName2 -ResourceGroupName $ResourceGroupName -Location $LocationName -SubnetId $vnet.Subnets[$subnetIndex].Id -PrivateIpAddress $PrivateIPforNIC2

## Create the availability group (if it does not exist) ##

New-AzureRmAvailabilitySet –Name $AvailabilitySet –ResourceGroupName $ResourceGroupName -Location $LocationName

## Specify the name, size & associate the Network Interface to the virtual machine ##

$vmName= $VirtualMachineName
$avSet=Get-AzureRmAvailabilitySet –Name $AvailabilitySet –ResourceGroupName $ResourceGroupName
$vm=New-AzureRMVMConfig -VMName $vmName -VMSize $vmSize -AvailabilitySetId $avset.Id
$vm=Add-AzureRMVMNetworkInterface -VM $vm -Id $nic.Id -Primary
$vm=Add-AzureRMVMNetworkInterface -VM $vm -Id $nic2.Id
## Specify the OS disk name

$storageAcc=Get-AzureRMStorageAccount -ResourceGroupName $ResourceGroupName -Name $saName

# Create VM from the existing OS disk

$vm=Set-AzureRmVMOSDisk -VM $vm -Name $diskName -VhdUri $sourceImageUri -CreateOption attach -Windows
New-AzureRmVM -ResourceGroupName $ResourceGroupName -Location $LocationName -VM $vm

I strongly recommend that you perform the above actions on a test virtual machine and confirm if this suits your requirement before making any changes to the actual virtual machine.

Comments (0)

Skip to main content