Last active
November 11, 2017 09:18
-
-
Save marckean/b0df6a0de7cdfaac0023eb6a19e3c467 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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