How Get "HTTP Listener" and "Route Path" of application gateway associated with WAF Policy with PowerShell.

白井 121 Reputation points
2021-01-18T09:42:51.95+00:00

Recently I started studying the WAF Policy for Application Gateway.

On the portal site, under "Application Gateway WAF policy", refer to "Associated application gateways" to find out the associated listeners and so on.

How can I get this information in PowerShell?

I thought I could get it with "Get-AzApplicationGatewayFirewallPolicy", but I couldn't find the corresponding information.

How Get "HTTP Listener" and "Route Path" of application gateway associated with WAF Policy with PowerShell.

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

Accepted answer
  1. suvasara-MSFT 10,046 Reputation points
    2021-01-18T11:12:22.513+00:00

    @白井 , Looks like the content regarding associated application gateways is missing in the output. Also, it might be provided in future module releases. Meanwhile you can try with the CLI commands,

       az network application-gateway waf-policy list  
    
    
       az network application-gateway waf-policy show  
    

    Ref : https://learn.microsoft.com/en-us/cli/azure/network/application-gateway/waf-policy?view=azure-cli-latest#az_network_application_gateway_waf_policy_list

    ----------

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


1 additional answer

Sort by: Most helpful
  1. 白井 121 Reputation points
    2021-01-22T06:00:33.893+00:00

    Self-answer
    After investigating, it seems that the information is contained in HttpListenersText and UrlPathMapsText in PSApplicationGateway obtained by Get-AzApplicationGateway.

    $GWName = 'appgateway'
    $RGName = 'resourcegroup'
    
    $appgw     = Get-AzApplicationGateway -ResourceGroupName $RGName -Name $GWName
    $listeners = ($appgw.HttpListenersText | ConvertFrom-Json) | Foreach {
        [PsCustomObject]@{
            Name         = $_.Name
            ListenerName = $_.Name
            ListenerId   = $_.Id
            PathName     = $null
            PathMapId    = $null
            FirewallPolicyName = ($_.FirewallPolicy.id -Split '/')[-1]
            FirewallPolicyId = $_.FirewallPolicy.id
        }
    }
    $pathmap   = ($appgw.UrlPathMapsText   | ConvertFrom-Json) | Foreach {
        $pathMapId = $_.id
        $rule      = $appgw.RequestRoutingRules.Find( { $pathMapId -eq $args.UrlPathMap.id } )
        $listener  = $appgw.HttpListeners.Find( { $rule.HttpListener.id -eq $args.id } )
        $_.PathRules | Foreach {
            [PsCustomObject]@{
                Name         = "{0}\{1}" -f $listener.Name, $_.Name
                ListenerName = $listener.Name
                ListenerId   = $listener.Id
                PathName     = $_.Name
                PathMapId    = $pathMapId
                FirewallPolicyName = ($_.FirewallPolicy.id -Split '/')[-1]
                FirewallPolicyId = $_.FirewallPolicy.id
            }
        }
    }
    $listeners + $pathmap | select ListenerName,PathName,FirewallPolicyName
    
    1 person found this answer helpful.
    0 comments No comments

Your answer

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