Create Multi-NIC Azure Virtual Machine (ARM)

A lot of people asked me to write a short post of how to create an Azure Virtual Machine with multiple NICs. After some googling an binging, I was not able to find a blog or an article which explains how to achieve it in a simple manner.

 
 
 
 
 
5 Star
(1)
1,503 times
Add to favorites
Windows Azure
2/14/2016
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • Recreate VM's with additional NICs
    1 Posts | Last post June 30, 2016
    • Hi Samir, is it possible to create a script that will export the VM config of an existing VM and re-create with adding additional NIC's. 
  • How to setup for SQL Server Instance
    4 Posts | Last post February 19, 2016
    • Hi, 
      
      We want to create a SQL Server VM Instance with two NICs. How to set the credentials for SQL Server and assign data disk to SQL Server
      
      $pubName="MicrosoftSQLServer"
      $offerName="SQL2012SP2-WS2012R2"
      $skuName="Web"
      $VM = Set-AzureRmVMOperatingSystem -VM $VM -Windows -ComputerName $vmName -Credential $cred -ProvisionVMAgent -EnableAutoUpdate
      $VM = Set-AzureRmVMSourceImage -VM $VM -PublisherName $pubName -Offer $offerName -Skus $skuName -Version "latest" 
      
      #Adding the VNICs to the config, you should always choose a Primary NIC
      $VM = Add-AzureRmVMNetworkInterface -VM $VM -Id $VNIC01.Id -Primary
      $VM = Add-AzureRmVMNetworkInterface -VM $VM -Id $VNIC02.Id
      
      
      # Specify the OS disk name and create the VM
      $DiskName='OSDisk-'+$VMName
      $SA = Get-AzureRmStorageAccount | where { $_.StorageAccountName -eq $SAName}
      $OSDiskUri = $SA.PrimaryEndpoints.Blob.ToString() + "vhds/" + $vmName+".vhd"
      $VM = Set-AzureRmVMOSDisk -VM $VM -Name $DiskName -VhdUri $osDiskUri -CreateOption fromImage
      New-AzureRmVM -ResourceGroupName $RGName -Location $Region -VM $VM
    • Hi,
      Please, what do you mean by 'How to set the credentials for SQL Server', do you mean the SQL server instance ?
      To add Data disks to the VM, you can add thsi before the VM creation :
      $DataDisk1Name = $vmName+'-data01'
      $Datadisk1URI = $SA.PrimaryEndpoints.Blob.ToString() + "vhds/" +$DataDisk1Name+".vhd"
      $DataDisk1Size = 10
      Add-AzureRmVMDataDisk -VM $VM -Name 'Name' -CreateOption empty -DiskSizeInGB $DataDisk1Size -VhdUri $Datadisk1URI
    • Hi,
      
      Thanks for your reply. I will tryout this script. 
      
      Regarding  'How to set the credentials for SQL Server', Yes, I meant the same. We want to enable the SQL authentication mode and want to set the separate credentials (not windows credentials) for the SQL instance.
    • I tried as you suggested. But I got Changing property 'osDisk.vhd.uri' is not allowed error.  I have pasted the script I used?
      
      New-AzureRmVM : Changing property 'osDisk.vhd.uri' is not allowed.
      StatusCode: 409
      ReasonPhrase: Conflict
      OperationID : '25f99cb3-5924-4dba-b50a-f9d58bcc1251'
      At D:\Documents\Karminn\Azure\DeployMultipleNicVMv0.1.ps1:169 char:1
      + New-AzureRmVM -ResourceGroupName $RGName -Location $Region -VM $VM
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          + CategoryInfo          : CloseError: (:) [New-AzureRmVM], ComputeCloudException
          + FullyQualifiedErrorId : Microsoft.Azure.Commands.Compute.NewAzureVMCommand
      
      Script I used
      
      
      $VM = New-AzureRmVMConfig -VMName $VMName -VMSize $VMSize 
      $pubName="MicrosoftSQLServer"
      $offerName="SQL2012SP2-WS2012R2"
      $skuName="Web"
      $VM = Set-AzureRmVMOperatingSystem -VM $VM -Windows -ComputerName $vmName -Credential $cred -ProvisionVMAgent -EnableAutoUpdate
      $VM = Set-AzureRmVMSourceImage -VM $VM -PublisherName $pubName -Offer $offerName -Skus $skuName -Version "latest"
      #Adding the VNICs to the config, you should always choose a Primary NIC
      $VM = Add-AzureRmVMNetworkInterface -VM $VM -Id $VNIC01.Id -Primary
      $VM = Add-AzureRmVMNetworkInterface -VM $VM -Id $VNIC02.Id
      
      
      
      # Specify the OS disk name and create the VM
      $SA = Get-AzureRmStorageAccount | where { $_.StorageAccountName -eq $SAName}
      
      $DataDisk1Name = $VMName+'-data01'
      $Datadisk1URI = $SA.PrimaryEndpoints.Blob.ToString() + "vhds/" +$DataDisk1Name+".vhd"
      $DataDisk1Size = 1024
      Add-AzureRmVMDataDisk -VM $VM -Name $DataDisk1Name -VhdUri $Datadisk1URI -DiskSizeInGB $DataDisk1Size -CreateOption empty
      
      $DiskName='OSDisk-'+$VMName
      $OSDiskUri = $SA.PrimaryEndpoints.Blob.ToString() + "vhds/" + $vmName+".vhd"
      $VM = Set-AzureRmVMOSDisk -VM $VM -Name $DiskName -VhdUri $osDiskUri -Windows -CreateOption fromImage -Caching ReadWrite
      
      New-AzureRmVM -ResourceGroupName $RGName -Location $Region -VM $VM