Update Path based rules under Path-based routing in AGW using Powershell/CLI

Bagh, Saujol 0 Reputation points
2023-04-12T03:59:09.4633333+00:00

Hello Team, I want to update the existing path based rule for eg: /test* is the path and it is having one backendsetting and backendtarget. I want to write a script in powershell/CLI where I can able to update new value of backendsetting and backendtarget for /test*

Azure Application Gateway
Azure Application Gateway
An Azure service that provides a platform-managed, scalable, and highly available application delivery controller as a service.
{count} votes

1 answer

Sort by: Most helpful
  1. KapilAnanth 49,851 Reputation points Moderator
    2023-04-12T06:33:20.1333333+00:00

    Bagh, Saujol Welcome to the Microsoft Q&A Platform. Thank you for reaching out & I hope you are doing well. The following commands and document would come in handy,

    Please find the PS script below, for modifying the PathBasedRules of a Rule

    $appgw = Get-AzApplicationGateway -ResourceGroupName <RGName> -Name <AppGwName>
    $poolSettings = Get-AzApplicationGatewayBackendHttpSettings -ApplicationGateway $appgw -Name <HttpSettingsForThePathRule>
    $defaultPool = Get-AzApplicationGatewayBackendAddressPool -ApplicationGateway 
    $appgw -Name <TheDefaultPool>
    
    $pathBasedPool1 = Get-AzApplicationGatewayBackendAddressPool -ApplicationGateway $appgw -Name <ThePoolYouWantToAddForPath1>
    $pathBasedPool2 = Get-AzApplicationGatewayBackendAddressPool -ApplicationGateway $appgw -Name <ThePoolYouWantToAddForPath2>
    
    $PathRule1 = New-AzApplicationGatewayPathRuleConfig -Paths "/path1/*" -Name pathPathRule1 -BackendAddressPool $pathBasedPool -BackendHttpSettings $poolSettings 
    
    $PathRule2 = New-AzApplicationGatewayPathRuleConfig -Paths "/path2/*" -Name pathPathRule2 -BackendAddressPool $pathBasedPool -BackendHttpSettings $poolSettings 
    
    $appgw = Set-AzApplicationGatewayUrlPathMapConfig -ApplicationGateway $appgw -Name <NameOfTheRuleinAppGw> -PathRules $PathRule1, $PathRule2 -DefaultBackendAddressPoolId $defaultPool.Id -DefaultBackendHttpSettingsId $poolSettings.Id
    
    Set-AzApplicationGateway -ApplicationGateway $appgw
    
    

    The above is a generic one. In your case, you can use one PathRule and get this done. So, your commands become,

    $PathRule1 = New-AzApplicationGatewayPathRuleConfig -Paths "/test*" -Name pathPathRule1 -BackendAddressPool $pathBasedPool -BackendHttpSettings $poolSettings 
    
    and 
    
    
    $appgw = Set-AzApplicationGatewayUrlPathMapConfig -ApplicationGateway $appgw -Name <NameOfTheRuleinAppGw> -PathRules $PathRule1 -DefaultBackendAddressPoolId $defaultPool.Id -DefaultBackendHttpSettingsId $poolSettings.Id
    
    

    Hope this helps. Thanks, Kapil


    Please don’t forget to close the thread by clicking "Accept the answer" wherever the information provided helps you, as this can be beneficial to other community members.

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.