Az Powershell add VMs to a backend pool

Jan Vávra 251 Reputation points
2024-01-09T23:13:46.8133333+00:00

I have following script that works only if there is only one machine in the foreach loop.
I can see at the backend pool at Azure portal that all machines are in backend pool but lb doesn't accept any connection. If I remove all from the backend pool except one, the lb starts accepting connections.

$loadBalancer = Get-AzLoadBalancer -ResourceGroupName $lbRgName -Name $lbName
$backendPool = Get-AzLoadBalancerBackendAddressPoolConfig -Name $lbBackPoolName -LoadBalancer $loadBalancer
if ($null -eq $backendPool)
{
    throw "Backend pool $lbBackPoolName not found for $lbName"
}

$virtualMachines = Get-AzVM -ResourceGroupName $rgName
foreach ($vm in $virtualMachines)
{
    $nic = Get-AzNetworkInterface -ResourceGroupName $rgName | Where-Object {$_.Id -eq $vm.NetworkProfile.NetworkInterfaces.Id}    
    $ipCfg = $nic.IpConfigurations | Where-Object {$_.Primary} 
    $ipCfg.LoadBalancerBackendAddressPools.Add($backendPool)
    Set-AzNetworkInterface -NetworkInterface $nic
}
Azure Load Balancer
Azure Load Balancer
An Azure service that delivers high availability and network performance to applications.
406 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,132 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Jan Vávra 251 Reputation points
    2024-01-12T09:48:48.7966667+00:00

    Hello, actually this is a SKU Basic LB. Hower I have tried to create a new load balancer and everythink works. So this is probably bug of a Azure Portal where I had the original LB created.

    0 comments No comments

  2. ChaitanyaNaykodi-MSFT 23,341 Reputation points Microsoft Employee
    2024-01-13T01:56:58.9966667+00:00

    @Jan Vávra

    Thank you for getting back and letting us know that the issue was resolved.

    Actually, IP based backends can only be used for Standard Load Balancers SKU. This is currently documented here. I think the new load balancer you created will be of Standard SKU.

    Hope this helps! Please let me know if you have any additional questions. Thank you!