简体   繁体   English

如何使用Powershell获得Azure VM的Loadbalancer名称?

[英]How can I get Loadbalancer Name of azure vm using powershell?

I'm new on azure deployment, so we are trying to get a name on the current Virtual machine to make a deployment so we need to remove and put on rotation current virtual machine. 我是azure部署的新手,因此我们试图在当前虚拟机上命名以进行部署,因此我们需要删除当前的虚拟机并将其旋转。

Today I was able to remove a VM of the balancer but not put on rotation. 今天,我能够删除平衡器的虚拟机,但无法旋转。

I know that I need the name of the balancer. 我知道我需要平衡器的名称。

Now I was able to get: Ip-Address. 现在我可以得到:Ip-Address。 Name of nic. 网卡名称。 Name on azure of the VM. 蔚蓝虚拟机上的名称。 Name of subscription. 订阅名称。

I got code below on powershell code that set on rotation: 我在下面设置了旋转设置的powershell代码中的代码:

$nic = Get-AzureRmNetworkInterface -Name $NicName -ResourceGroup $RGName 
$lb = Get-AzureRmLoadBalancer -Name $Namelb -ResourceGroupName $RGlb
$nic.IpConfigurations[0].LoadBalancerBackendAddressPools = $lb.BackendAddressPools 
Set-AzureRmNetworkInterface -NetworkInterface $nic

But I have no the name of the balancer. 但是我没有平衡器的名字。

And on this way I was able to remove 这样我就可以删除

$nic = Get-AzureRmNetworkInterface -Name $NicName -ResourceGroup $RGName 
$lb = Get-AzureRmLoadBalancer -Name $Namelb -ResourceGroupName $RGlb
$nic.IpConfigurations[0].LoadBalancerBackendAddressPools = $lb.BackendAddressPools 
Set-AzureRmNetworkInterface -NetworkInterface $nic

If I have another information but Name of balancer not. 如果我还有其他信息,但没有平衡器名称。

What can I do for getting this name of balancer? 我如何做才能得到这个平衡器的名字?

Thanks, 谢谢,

Marco Carballo 马可·卡波洛(Marco Carballo)

If you have added a VM to the load balancer, then you want to get the name of the load balancer, you could try the command below, the $Namelb will be the name of the load balancer. 如果已将VM添加到负载均衡器, $Namelb获取负载均衡器的名称,可以尝试以下命令, $Namelb将是负载均衡器的名称。

$NicName = "<name of the NIC>"
$RGName = "<resource group name>"
$nic = Get-AzureRmNetworkInterface -Name $NicName -ResourceGroup $RGName 
$a = $nic.IpConfigurations[0].LoadBalancerBackendAddressPools.Id -split"/"
$Namelb = $a[8]

在此处输入图片说明

Besides, if you have removed the VM from the load balancer, you could just use the command below to list all the load balancers in the resource group or subscription and find that one you want. 此外,如果您已从负载均衡器中删除了VM,则可以使用以下命令列出资源组或订阅中的所有负载均衡器,然后找到所需的负载均衡器。

List via resource group: 通过资源组列出:

Get-AzureRmLoadBalancer -ResourceGroupName <resource group name> | Select-Object Name

List via subscription: 通过订阅列出:

Get-AzureRmLoadBalancer | Select-Object Name

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM