About Me

My photo
I am MCSE in Data Management and Analytics with specialization in MS SQL Server and MCP in Azure. I have over 13+ years of experience in IT industry with expertise in data management, Azure Cloud, Data-Canter Migration, Infrastructure Architecture planning and Virtualization and automation. Contact me if you are looking for any sort of guidance in getting your Infrastructure provisioning automated through Terraform. I sometime write for a place to store my own experiences for future search and read by own blog but can hopefully help others along the way. Thanks.

Add a NIC to an existing VM in Azure gets error Update-AzureRmVm : Virtual machine sqlnode1 must have one network interface set as the primary. ErrorCode: VirtualMachineMustHaveOneNetworkInterfaceAsPrimary




while adding additional NIC to the existing VM in Azure  i received  below error.

Error that comes in Powershell..


Update-AzureRmVm : Virtual machine sqlnode1 must have one network interface set as the primary.
ErrorCode: VirtualMachineMustHaveOneNetworkInterfaceAsPrimary
ErrorMessage: Virtual machine sqlnode1 must have one network interface set as the primary.
StatusCode: 400
ReasonPhrase: Bad Request
OperationID : b4b511bd-5333-4f18-b04c-22a8bf627923
At line:1 char:52
+ ... e -VM $vm -Id $nicId | Update-AzureRmVm -ResourceGroupName "rakctlrg"
+                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : CloseError: (:) [Update-AzureRmVM], ComputeCloudException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.Compute.UpdateAzureVMCommand


In order to resolve this issue, we have to execute below steps:-

=============================================

$vm = Get-AzureRmVm -Name "sqlnode1" -ResourceGroupName "rakctlrg"
$VM.NetworkProfile.NetworkInterfaces.Item(0).primary = $true
Update-AzureRmVM -ResourceGroupName "rakctlrg" -VM $VM

Important point to note:-
=================


1. VM should be in deallocated state.
2. we can add multiple NIC in a VM, but it depends on the size of VM, example D2s v3  can support maximum of 2 NIC.
3. when adding 2nd NIC, first NIC should be on primary NIC.


Thanks for Reading..