How to get the load balancers connected to the Azure VM using PowerShell?

To get the load balancers attached to the Azure VM using PowerShell, we first need to retrieve the Azure VM network settings. For example, we have an Azure VM name “TestVM” and we will

PS C:\> $vm = Get-AzVM -Name TestVM
$nic = (($'/'))[-1]

Once we have the network interface name, we need to retrieve the load balancer settings, and to get the Load Balancer settings we need to use the Get-AzNetworkInterface command.

PS C:\> $nicsettings = Get-AzNetworkInterface -Name $nic

The below command will retrieve the load balancer name.


To get the Load Balancer backend pool name, use the below command.


Overall Script −

$vm = Get-AzVM -Name ‘TestVM’
$vmnic = ($'/')[-1]
$nicsettings = Get-AzNetworkInterface -Name $vmnic
Write-Output "Load Balancer: : $((($'/'))[-3])"
Write-Output "Backend Pool: $((($'/'))[-1])"