Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
# Recently tested fully with a later version of the Azure PowerShell module - Install-Module AzureRM -RequiredVersion 4.4.1
#region Logon to Azure
$subscription = Get-AzureRmSubscription | Out-GridView -PassThru
Select-AzureRmSubscription -SubscriptionId $subscription.Id
# Variables for YOu to fill in
$ResourceGroup = 'MyResourceGroupName' # resource group name to contain the new NIC
$VMname = 'VMware-01' # VM you want to add the new NIC to
$NICName = 'VMware-NIC' # for the new NIC
$Location = 'southeastasia' # for the new NIC
# Get the VNET to which to connect the NIC
$VNET = Get-AzureRmVirtualNetwork -Name 'NestedVMware-vnet' -ResourceGroupName $ResourceGroup
# Get the Subnet ID to which to connect the NIC
$SubnetID = (Get-AzureRmVirtualNetworkSubnetConfig -Name 'default' -VirtualNetwork $VNET).Id
#–> Create now the NIC Interface
New-AzureRmNetworkInterface -Name $NICName -ResourceGroupName $ResourceGroup -Location $Location -SubnetId $SubnetID
#Get the VM config to a variable
$VM = Get-AzureRmVM -Name $VMname -ResourceGroupName $ResourceGroup
#Stop the VM
Stop-AzureRmVM -Name $VM.Name -ResourceGroupName $VM.ResourceGroupName -StayProvisioned -Force
#Add the second NIC to the VM variable
$NewNIC = Get-AzureRmNetworkInterface -Name $NICName -ResourceGroupName $ResourceGroup
$VM = Add-AzureRmVMNetworkInterface -VM $VM -Id $NewNIC.Id
# Show the Network interfaces
#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 $ResourceGroup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment