Skip to content

Instantly share code, notes, and snippets.

@SQLtattoo
Last active June 26, 2020 06:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SQLtattoo/9c8416b530fd66bf727a9028793b4037 to your computer and use it in GitHub Desktop.
Save SQLtattoo/9c8416b530fd66bf727a9028793b4037 to your computer and use it in GitHub Desktop.
Add a TCP rule to an existing Azure Load Balancer
#Make sure we are on the correct Azure Subscription
Get-AzContext
$lbName = "your-lb-name-here"
$rgName = "your-resource-group-name"
$probName = "the-lb-probe-name"
$bepName = "backend-pool" ### the backend pool that has the VMs
$port = 10000 ### the port to load balance on the backend pool servers
$ruleName = "rule-name" ###the name of the new rule
$slb = Get-AzLoadBalancer -Name $lbName -ResourceGroupName $rgName
$prb = Get-AzLoadBalancerProbeConfig -Name $probName -LoadBalancer $slb
$beaddpool = Get-AzLoadBalancerBackendAddressPoolConfig -Name $bepName -LoadBalancer $slb
# Add the rule to the configuration
$slb | Add-AzLoadBalancerRuleConfig -Name $ruleName `
-FrontendIPConfiguration $slb.FrontendIpConfigurations[0] `
-BackendAddressPool $beaddpool `
-Protocol "Tcp" `
-FrontendPort $port `
-BackendPort $port `
-Probe $prb
# Set the rule configuration
$slb | Set-AzLoadBalancerRuleConfig -Name $ruleName `
-FrontendIPConfiguration $slb.FrontendIpConfigurations[0] `
-BackendAddressPool $beaddpool `
-Protocol "Tcp" `
-FrontendPort $port `
-BackendPort $port `
-Probe $prb
# Note: you can add couples like the above Add/Set
# so that your rules are added in one GO before
# touching the load balancer once with a single Set
#apply the changes to the load balancer
$slb | Set-AzLoadBalancer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment