为Azure虚拟机添加第二块网卡

来源:互联网 发布:网络改号电话 编辑:程序博客网 时间:2024/05/16 07:15

为Azure虚拟机添加第二块网卡

有时候我们将虚拟机创建好之后发现还需要第二块网卡,使用下面的脚本我们可以轻松的添加第二块网卡到ARM虚拟机。
脚本运行步骤:
1. 弹出登录窗口中输入登录凭据
2.选择要添加网卡的虚拟机
3.选择网卡所在的子网
4.去倒杯水吧......


#------------------------------------------------------------------------------    # User own the risk, otherwise exit.# # Azure PowerShell Version:  3.6.0## Create by Zeno. #------------------------------------------------------------------------------  Login-AzureRmAccount -EnvironmentName AzureChinaCloud -Credential $(Get-Credential -UserName admin@xxx.partner.onmschina.cn -Message Login_AzureChinaCloud) |Out-Null#获取虚拟机信息$vm = Get-AzureRmVM | Select-Object Name,ResourceGroupName,Location,NetworkInterfaceIDs | Out-GridView -PassThru -Title "Select your VM" $rgName = $vm.ResourceGroupName$location = $vm.Location$nic2 = ($vm.Name + "-nic2").ToLower()$Subnet = Get-AzureRmVirtualNetwork | Get-AzureRmVirtualNetworkSubnetConfig | Select-Object Name,Id,AddressPrefix| Out-GridView -PassThru -Title "Select your New NIC's Subnet"#解除分配write-host "`n`tStop the Select VM!" -ForegroundColor Green$stopvm = Stop-AzureRmVM -Name $vm.Name -ResourceGroupName $rgName#添加新的NICwrite-host "`n`tAdd the Second NIC to VM!" -ForegroundColor Green$nic2 = New-AzureRmNetworkInterface -ResourceGroupName $rgName -Name $nic2 -Location $location -SubnetId $Subnet.Id$addnic = Get-AzureRmVM -Name $vm.Name -ResourceGroupName $rgName | Add-AzureRmVMNetworkInterface -Id $nic2.Id -Primary |Update-AzureRmVM#切换主网卡write-host "`n`tChange the Primary NIC!" -ForegroundColor Green$myvm = Get-AzureRmVM -Name $vm.Name -ResourceGroupName $rgName$myvm.NetworkProfile.NetworkInterfaces[0].Primary = $true$myvm.NetworkProfile.NetworkInterfaces[1].Primary = $false$changenic = Update-AzureRmVM -VM $myvm -ResourceGroupName $rgName#启动虚拟机write-host "`n`tStart the VM!" -ForegroundColor Green$startvm = Get-AzureRmVM -Name $vm.Name -ResourceGroupName $rgName | Start-AzureRmVM


原创粉丝点击