Adding NICs to VMs

To add a new NIC to the myVM1 virtual machine, run the following four commands:

$nicId = (Get-AzureRmNetworkInterface `
-ResourceGroupName "VMLab" `
-Name "MyNewNIC").Id

$VM = Add-AzureRmVMNetworkInterface -VM $VM -Id $nicId

$VM.NetworkProfile.NetworkInterfaces.Item(0).primary = $true

Update-AzureRmVM -ResourceGroupName "vmlab" -VM $VM

The first command retrieves the Azure ID of the newly created NIC. The NIC is then added to the myVM1 virtual machine configuration with the second command. With the third command, the existing NIC (the one originally created with the VM) is set as the primary NIC (note that all VMs must have a primary NIC). Finally, the fourth command, Update-AzureRmVm, is used to update the myVM1 virtual machine configuration to include the newly attached NIC.

A quick check of the network settings for MyVM3 in the Azure portal should show the new NIC attached, as follows:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.107.90