First at all, log in Azure
Login-AzureRmAccount
Choice the subscription to use and declare the variables
Select-AzureRmSubscription –SubscriptionId <id_of_your_subscription>
$VMname = ‘VMName’
$VMRG = ‘ResourceGroupName’
$NICName = ‘NICName’
$NICResourceGroup = ‘NICResourceGroupName’
Get the VM
$VM = Get-AzureRmVM -Name $VMname -ResourceGroupName $VMRG
Add the second NIC
$NewNIC = Get-AzureRmNetworkInterface -Name $NICName -ResourceGroupName $NICResourceGroup
$VM = Add-AzureRmVMNetworkInterface -VM $VM -Id $NewNIC.Id
Show Network interfaces
$VM.NetworkProfile.NetworkInterfaces
We have to set one of the NICs to Primary, I will set the first NIC in this example
$VM.NetworkProfile.NetworkInterfaces.Item(0).Primary = $true
Update the VM configuration (The VM will be restarted)
Update-AzureRmVM -VM $VM -ResourceGroupName $VMRG