<div dir="ltr" style="text-align: left;">
<div style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-outline-level: 2;"><b><span style="font-family: ";times new roman"; , ";serif";; font-size: 18.0pt;">Create/ Add a New NIC and Private IP Address to Existing Azure VM<o:p></o:p></span></b></div>
<div style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"><span style="font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;">The first step is to open Windows PowerShell ISE and log in to your Azure subscription using the <b>Login-AzureRmAccount</b> cmdlet. Let’s define some variables for our VM, network, and other parameters that will be required.<o:p></o:p></span><br /><span style="font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;"><br /></span></p>
<div style="clear: both; text-align: center;"><a href="http://www.thecloudxperts.co.uk/wp-content/uploads/2017/10/download-2B-25281-2529.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="224" data-original-width="225" src="http://www.thecloudxperts.co.uk/wp-content/uploads/2017/10/download-2B-25281-2529.jpg" /></a></div>
<p><span style="font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;"><br /></span></div>
<div style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"><span style="font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;">$RG defines the Resource Group where the VM and VNET are located. The new NIC will be created in this Resource Group. I picked a name for the new NIC ($nicName), and a private IP address, which I know is available ($ipAddress). If you are not sure what the rest of the values should be for your deployment, locate the VM in the Azure management portal, and you’ll find information about the deployment, network, and any other related resources.<o:p></o:p></span></div>
<div style="line-height: normal; margin-bottom: 9.0pt;"><span style="font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;">PowerShell<o:p></o:p></span></div>
<table border="0" cellpadding="0">
<tbody>
<tr>
<td style="padding: .75pt .75pt .75pt .75pt;">
<div style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm;"><span style="background: yellow; font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;">1<o:p></o:p></span></div>
<div style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm;"><span style="background: yellow; font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;">2<o:p></o:p></span></div>
<div style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm;"><span style="background: yellow; font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;">3<o:p></o:p></span></div>
<div style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm;"><span style="background: yellow; font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;">4<o:p></o:p></span></div>
<div style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm;"><span style="background: yellow; font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;">5<o:p></o:p></span></div>
<div style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm;"><span style="background: yellow; font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;">6<o:p></o:p></span></div>
<div style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm;"><span style="background: yellow; font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;">7<o:p></o:p></span></div>
</td>
<td style="padding: .75pt .75pt .75pt .75pt;">
<div style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm;"><span style="background: yellow; font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;">$vmName = ‘myVM’ <o:p></o:p></span></div>
<div style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm;"><span style="background: yellow; font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;">$vnetName = ‘myVNET’ <o:p></o:p></span></div>
<div style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm;"><span style="background: yellow; font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;">$RG = ‘PetriRG’ <o:p></o:p></span></div>
<div style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm;"><span style="background: yellow; font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;">$subnetName = ‘Subnet-1’ <o:p></o:p></span></div>
<div style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm;"><span style="background: yellow; font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;">$nicName = ‘PetriVM-NIC3’ <o:p></o:p></span></div>
<div style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm;"><span style="background: yellow; font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;">$location = ‘North Europe’ <o:p></o:p></span></div>
<div style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm;"><span style="background: yellow; font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;">$ipAddress = ’10.0.0.6’</span><span style="font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;"><o:p></o:p></span></div>
</td>
</tr>
</tbody>
</table>
<div style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"><span style="font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;">The next step is to create an object for the VM using <i>Get-AzureRmVM</i>:<o:p></o:p></span></div>
<div style="line-height: normal; margin-bottom: 9.0pt;"><span style="font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;">PowerShell<o:p></o:p></span></div>
<table border="0" cellpadding="0">
<tbody>
<tr>
<td style="padding: .75pt .75pt .75pt .75pt;">
<div style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm;"><span style="background: yellow; font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;">1<o:p></o:p></span></div>
</td>
<td style="padding: .75pt .75pt .75pt .75pt;">
<div style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm;"><span style="background: yellow; font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;">$myVm = Get-AzureRmVM -Name $vmName -ResourceGroupName $RG</span><span style="font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;"><o:p></o:p></span></div>
</td>
</tr>
</tbody>
</table>
<div style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"><span style="font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;">And now we’ll create an object for the virtual network using <i>Get-AzureRmVirtualNetwork</i>:<o:p></o:p></span></div>
<div style="line-height: normal; margin-bottom: 9.0pt;"><span style="font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;">PowerShell<o:p></o:p></span></div>
<table border="0" cellpadding="0">
<tbody>
<tr>
<td style="padding: .75pt .75pt .75pt .75pt;">
<div style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm;"><span style="background: yellow; font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;">1<o:p></o:p></span></div>
</td>
<td style="padding: .75pt .75pt .75pt .75pt;">
<div style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm;"><span style="background: yellow; font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;">$vnet = Get-AzureRmVirtualNetwork -Name $vnetName -ResourceGroupName $RG</span><span style="font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;"><o:p></o:p></span></div>
</td>
</tr>
</tbody>
</table>
<div style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"><span style="font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;">The new NIC needs to be connected to a subnet ($subnetName), but we need to know the subnet ID before we can work with it in PowerShell:<o:p></o:p></span></div>
<div style="line-height: normal; margin-bottom: 9.0pt;"><span style="font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;">PowerShell<o:p></o:p></span></div>
<table border="0" cellpadding="0">
<tbody>
<tr>
<td style="padding: .75pt .75pt .75pt .75pt;">
<div style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm;"><span style="background: yellow; font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;">1<o:p></o:p></span></div>
</td>
<td style="padding: .75pt .75pt .75pt .75pt;">
<div style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm;"><span style="background: yellow; font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;">$subnetID = (Get-AzureRmVirtualNetworkSubnetConfig -Name $subnetName -VirtualNetwork $vnet).Id</span><span style="font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;"><o:p></o:p></span></div>
</td>
</tr>
</tbody>
</table>
<div style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"><span style="font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;">Finally, we can create a new NIC using the <i>New-AzureRmNetworkInterface</i> cmdlet:<o:p></o:p></span></div>
<div style="line-height: normal; margin-bottom: 9.0pt;"><span style="background: yellow; font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;">PowerShell</span><span style="font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;"><o:p></o:p></span></div>
<table border="0" cellpadding="0">
<tbody>
<tr>
<td style="padding: .75pt .75pt .75pt .75pt;">
<div style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm;"><span style="background: yellow; font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;">1<o:p></o:p></span></div>
</td>
<td style="padding: .75pt .75pt .75pt .75pt;">
<div style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm;"><span style="background: yellow; font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;">New-AzureRmNetworkInterface -Name $nicName -ResourceGroupName $RG -Location $location -SubnetId $subnetID -PrivateIpAddress $ipAddress</span><span style="font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;"><o:p></o:p></span></div>
</td>
</tr>
</tbody>
</table>
<div style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm;"></div>
<div style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"><span style="font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;">Add a network interface in Azure (Image Credit: Russell Smith)<o:p></o:p></span></div>
<div style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-outline-level: 2;"><b><span style="font-family: ";times new roman"; , ";serif";; font-size: 18.0pt;">Attach the NIC to a VM<o:p></o:p></span></b></div>
<div style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"><span style="font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;">Now that a new NIC has been created, all that’s left to do is to attach it to the VM. First, we’ll create an object for the NIC using the <i>Get-AzureRmNetworkInterface</i>cmdlet:<o:p></o:p></span></div>
<div style="line-height: normal; margin-bottom: 9.0pt;"><span style="font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;">PowerShell<o:p></o:p></span></div>
<table border="0" cellpadding="0">
<tbody>
<tr>
<td style="padding: .75pt .75pt .75pt .75pt;">
<div style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm;"><span style="background: yellow; font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;">1<o:p></o:p></span></div>
</td>
<td style="padding: .75pt .75pt .75pt .75pt;">
<div style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm;"><span style="background: yellow; font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;">$myNIC = ; ;Get-AzureRmNetworkInterface -Name $nicName -ResourceGroupName $RG</span><span style="font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;"><o:p></o:p></span></div>
</td>
</tr>
</tbody>
</table>
<div style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"><span style="font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;">Let’s add the NIC to the VM configuration:<o:p></o:p></span></div>
<div style="line-height: normal; margin-bottom: 9.0pt;"><span style="font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;">PowerShell<o:p></o:p></span></div>
<table border="0" cellpadding="0">
<tbody>
<tr>
<td style="padding: .75pt .75pt .75pt .75pt;">
<div style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm;"><span style="background: yellow; font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;">1<o:p></o:p></span></div>
</td>
<td style="padding: .75pt .75pt .75pt .75pt;">
<div style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm;"><span style="background: yellow; font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;">$myVm = Add-AzureRmVMNetworkInterface -VM $myVm -Id $myNIC.Id</span><span style="font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;"><o:p></o:p></span></div>
</td>
</tr>
</tbody>
</table>
<div style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"><span style="font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;">If you want to check that the configuration has been changed to include the new NIC, you can run the command below to see the list of NICs attached to the VM:<o:p></o:p></span></div>
<div style="line-height: normal; margin-bottom: 9.0pt;"><span style="font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;">PowerShell<o:p></o:p></span></div>
<table border="0" cellpadding="0">
<tbody>
<tr>
<td style="padding: .75pt .75pt .75pt .75pt;">
<div style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm;"><span style="background: yellow; font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;">1<o:p></o:p></span></div>
</td>
<td style="padding: .75pt .75pt .75pt .75pt;">
<div style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm;"><span style="background: yellow; font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;">$myVM.NetworkProfile.NetworkInterfaces</span><span style="font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;"><o:p></o:p></span></div>
</td>
</tr>
</tbody>
</table>
<div style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"><span style="font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;">Note that the primary NIC (0) is the first NIC in the list. If you want to set another NIC as the primary NIC, for instance, the third NIC (2), run the command below:<o:p></o:p></span></div>
<div style="line-height: normal; margin-bottom: 9.0pt;"><span style="font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;">PowerShell<o:p></o:p></span></div>
<table border="0" cellpadding="0">
<tbody>
<tr>
<td style="padding: .75pt .75pt .75pt .75pt;">
<div style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm;"><span style="background: yellow; font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;">1<o:p></o:p></span></div>
</td>
<td style="padding: .75pt .75pt .75pt .75pt;">
<div style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm;"><span style="background: yellow; font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;">$myVM.NetworkProfile.NetworkInterfaces.Item(2).Primary = $true</span><span style="font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;"><o:p></o:p></span></div>
</td>
</tr>
</tbody>
</table>
<div style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"><span style="font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;">Lastly, let’s commit the new configuration using the <i>Update-AzureRmVM</i> cmdlet:<o:p></o:p></span></div>
<div style="line-height: normal; margin-bottom: 9.0pt;"><span style="font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;">PowerShell<o:p></o:p></span></div>
<table border="0" cellpadding="0">
<tbody>
<tr>
<td style="padding: .75pt .75pt .75pt .75pt;">
<div style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm;"><span style="background: yellow; font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;">1<o:p></o:p></span></div>
</td>
<td style="padding: .75pt .75pt .75pt .75pt;">
<div style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0cm;"><span style="background: yellow; font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;">Update-AzureRmVM -VM $myVm -ResourceGroupName $RG</span><span style="font-family: ";times new roman"; , ";serif";; font-size: 12.0pt;"><o:p></o:p></span></div>
</td>
</tr>
</tbody>
</table>
<p></p>
<div></div>
</div>

