简体   繁体   中英

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.

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. Name of nic. Name on azure of the VM. Name of subscription.

I got code below on powershell code that set on rotation:

$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

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.

$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.

List via resource group:

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

List via subscription:

Get-AzureRmLoadBalancer | Select-Object Name

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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