Adding new rule in exisitng app gateway through powershall

Vikas Tiwari 766 Reputation points
2020-06-02T14:40:30.047+00:00

Hi,

I have an existing app gateway has 4 path based rule setup. I need to add new entry in app gateway through powershell, I have used following commands but after running it removes all existing entries and adds only new rule (overrides all 4 rules and add only new entry):

$appgw = Set-AzApplicationGatewayUrlPathMapConfig -ApplicationGateway $appgw -Name "pathBasedRule" -PathRules $myPathRule -DefaultBackendAddressPool $backendPool -DefaultBackendHttpSettings $backendPoolSetting

Set-AzApplicationGateway -ApplicationGateway $appgw

I couldn't find any power shell command where I can fetch all 4 rules then I will add 1 new rule, so that
my app gateway will have 5 rules after running. how can I do that through PS?

Thnaks

Azure Application Gateway
Azure Application Gateway
An Azure service that provides a platform-managed, scalable, and highly available application delivery controller as a service.
937 questions
Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,095 questions
0 comments No comments
{count} votes

Accepted answer
  1. Vikas Tiwari 766 Reputation points
    2020-06-10T02:02:48.317+00:00

    I have found the solution through ARM template. If anyone facing similar kind of issue here are the details:

    As I didn't find any ps command to add new rule in existing path based rule, we can add completely new rule using Add-AzApplicationGatewayUrlPathMapConfig but I want to just add new path based condition. below is json template that has 2 rules:

        "urlPathMaps": [
          {
            "name": "urlPathMap1",
            "properties": {
              "defaultBackendAddressPool": {
                "id": "[concat(variables('applicationGatewayID'), '/backendAddressPools/appGatewayBackendPoolDefault')]"
              },
              "defaultBackendHttpSettings": {
                "id": "[concat(variables('applicationGatewayID'), '/backendHttpSettingsCollection/appGatewayBackendHttpSettings')]"
              },
              "pathRules": [
                {
                  "name": "pathRule1",
                  "properties": {
                    "paths": [
                      "[parameters('pathMatch1')]"
                    ],
                    "backendAddressPool": {
                      "id": "[concat(variables('applicationGatewayID'), '/backendAddressPools/appGatewayBackendPool1')]"
                    },
                    "backendHttpSettings": {
                      "id": "[concat(variables('applicationGatewayID'), '/backendHttpSettingsCollection/appGatewayBackendHttpSettings')]"
                    }
                  }
                },
                {
                  "name": "pathRule2",
                  "properties": {
                    "paths": [
                      "[parameters('pathMatch2')]"
                    ],
                    "backendAddressPool": {
                      "id": "[concat(variables('applicationGatewayID'), '/backendAddressPools/appGatewayBackendPool2')]"
                    },
                    "backendHttpSettings": {
                      "id": "[concat(variables('applicationGatewayID'), '/backendHttpSettingsCollection/appGatewayBackendHttpSettings')]"
                    }
                  }
                }
              ]
            }
          }
        ]
    

    we can add another rule to add new path condition in existing app gateway, here is github link for complete sample template.

    https://github.com/Azure/azure-quickstart-templates/blob/master/201-application-gateway-url-path-based-routing/azuredeploy.json

    Hope this will help someone.

    Thanks.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. suvasara-MSFT 9,986 Reputation points
    2020-06-04T12:15:17.063+00:00

    Greetings,

    You need to use "Add" instead of "Set" here in order to avoid overriding of previous rules. The Add-AzApplicationGatewayUrlPathMapConfig cmdlet adds an array of URL path mappings to a back end server pool. Here is an example script for your reference,

    $appgw = Add-AzApplicationGatewayUrlPathMapConfig -ApplicationGateway $appgw -Name "APPGW-Name" -PathRules $pathRule - DefaultBackendAddressPool $pool -DefaultBackendHttpSettings $poolSettings
    
    
    $appgw = Set-AzApplicationGateway -ApplicationGateway $appgw
    

    This will allow you to add the new rules with out overriding the previous one.


    Please do not forget to "Accept the answer" wherever the information provided helps you to help others in the community.