为Azure虚拟机添加第二块网卡
2017-06-09 15:51
211 查看
为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 #添加新的NIC write-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
相关文章推荐
- 为CentOS虚拟机添加第二块网卡
- 为CentOS虚拟机添加第二块网卡
- Azure虚拟机添加磁盘
- Xen虚拟机添加网卡
- edhat/Centos第二块网卡添加/绑定IP
- 虚拟机添加网卡
- 当Azure里的虚拟机网卡被禁用
- 如何为Azure虚拟机添加数据磁盘
- vmware虚拟机添加第二块网卡不能上网的解决
- 给虚拟机添加eth1网络适配器(网卡)
- [Azure]使用Powershell批量添加虚拟机ACL
- 为openfiler添加第二块网卡
- 继之前SCVMM WinRM问题后重新添加群集后Windows Azure Pack创建虚拟机失败
- 虚拟机如何添加一块新的网卡并开启NAT网络模式
- RHEL7虚拟机添加新网卡后,网卡无法启动
- hyper-v新建虚拟机怎么添加网卡
- 虚拟机下centos 6网卡的添加
- 在虚拟机vmware中为solaris添加网卡备记
- XenServer虚拟机添加虚拟网卡
- 当Azure里的虚拟机网卡被禁用了之后……