Skip to content

Instantly share code, notes, and snippets.

@marckean
Last active November 11, 2017 09:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marckean/b0df6a0de7cdfaac0023eb6a19e3c467 to your computer and use it in GitHub Desktop.
Save marckean/b0df6a0de7cdfaac0023eb6a19e3c467 to your computer and use it in GitHub Desktop.
# Recently tested fully with a later version of the Azure PowerShell module - Install-Module AzureRM -RequiredVersion 4.4.1
#region Logon to Azure
Login-AzureRmAccount
$subscription = Get-AzureRmSubscription | Out-GridView -PassThru
Select-AzureRmSubscription -SubscriptionId $subscription.Id
#endregion
# 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
$VM.NetworkProfile.NetworkInterfaces
#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