|
| 1 | +--- |
| 2 | +title: Azure PowerShell Script Sample - Create WAF custom rules |
| 3 | +description: Azure PowerShell Script Sample - Create Web Application Firewall custom rules |
| 4 | +author: vhorne |
| 5 | +ms.service: application-gateway |
| 6 | +ms.topic: sample |
| 7 | +ms.date: 6/7/2019 |
| 8 | +ms.author: victorh |
| 9 | +--- |
| 10 | + |
| 11 | +# Create WAF custom rules with Azure PowerShell |
| 12 | + |
| 13 | +This script creates an Application Gateway Web Application Firewall that uses custom rules. The custom rule blocks traffic if the request header contains User-Agent *evilbot*. |
| 14 | + |
| 15 | +## Prerequisites |
| 16 | + |
| 17 | +### Azure PowerShell module |
| 18 | + |
| 19 | +If you choose to install and use Azure PowerShell locally, this script requires the Azure PowerShell module version 2.1.0 or later. |
| 20 | + |
| 21 | +1. To find the version, run `Get-Module -ListAvailable Az`. If you need to upgrade, see [Install Azure PowerShell module](/powershell/azure/install-az-ps). |
| 22 | +2. To create a connection with Azure, run `Connect-AzAccount`. |
| 23 | + |
| 24 | +[!INCLUDE [quickstarts-free-trial-note](../../../includes/quickstarts-free-trial-note.md)] |
| 25 | + |
| 26 | +## Sample script |
| 27 | + |
| 28 | +[!code-powershell[main](../../../powershell_scripts/application-gateway/waf-rules/waf-custom-rules.ps1 "Custom WAF rules")] |
| 29 | + |
| 30 | +## Clean up deployment |
| 31 | + |
| 32 | +Run the following command to remove the resource group, application gateway, and all related resources. |
| 33 | + |
| 34 | +```powershell |
| 35 | +Remove-AzResourceGroup -Name CustomRulesTest |
| 36 | +``` |
| 37 | + |
| 38 | +## Script explanation |
| 39 | + |
| 40 | +This script uses the following commands to create the deployment. Each item in the table links to command specific documentation. |
| 41 | + |
| 42 | +| Command | Notes | |
| 43 | +|---|---| |
| 44 | +| [New-AzResourceGroup](/powershell/module/az.resources/new-azresourcegroup) | Creates a resource group in which all resources are stored. | |
| 45 | +| [New-AzVirtualNetworkSubnetConfig](/powershell/module/az.network/new-azvirtualnetworksubnetconfig) | Creates the subnet configuration. | |
| 46 | +| [New-AzVirtualNetwork](/powershell/module/az.network/new-azvirtualnetwork) | Creates the virtual network using with the subnet configurations. | |
| 47 | +| [New-AzPublicIpAddress](/powershell/module/az.network/new-azpublicipaddress) | Creates the public IP address for the application gateway. | |
| 48 | +| [New-AzApplicationGatewayIPConfiguration](/powershell/module/az.network/new-azapplicationgatewayipconfiguration) | Creates the configuration that associates a subnet with the application gateway. | |
| 49 | +| [New-AzApplicationGatewayFrontendIPConfig](/powershell/module/az.network/new-azapplicationgatewayfrontendipconfig) | Creates the configuration that assigns a public IP address to the application gateway. | |
| 50 | +| [New-AzApplicationGatewayFrontendPort](/powershell/module/az.network/new-azapplicationgatewayfrontendport) | Assigns a port to be used to access the application gateway. | |
| 51 | +| [New-AzApplicationGatewayBackendAddressPool](/powershell/module/az.network/new-azapplicationgatewaybackendaddresspool) | Creates a backend pool for an application gateway. | |
| 52 | +| [New-AzApplicationGatewayBackendHttpSettings](/powershell/module/az.network/new-azapplicationgatewaybackendhttpsetting) | Configures settings for a backend pool. | |
| 53 | +| [New-AzApplicationGatewayHttpListener](/powershell/module/az.network/new-azapplicationgatewayhttplistener) | Creates a listener. | |
| 54 | +| [New-AzApplicationGatewayRequestRoutingRule](/powershell/module/az.network/new-azapplicationgatewayrequestroutingrule) | Creates a routing rule. | |
| 55 | +| [New-AzApplicationGatewaySku](/powershell/module/az.network/new-azapplicationgatewaysku) | Specify the tier and capacity for an application gateway. | |
| 56 | +| [New-AzApplicationGateway](/powershell/module/az.network/new-azapplicationgateway) | Create an application gateway. | |
| 57 | +|[Remove-AzResourceGroup](/powershell/module/az.resources/remove-azresourcegroup) | Removes a resource group and all resources contained within. | |
| 58 | +|[New-AzApplicationGatewayAutoscaleConfiguration](/powershell/module/az.network/New-AzApplicationGatewayAutoscaleConfiguration)|Creates an autoscale configuration for the Application Gateway.| |
| 59 | +|[New-AzApplicationGatewayFirewallMatchVariable](/powershell/module/az.network/New-AzApplicationGatewayFirewallMatchVariable)|Creates a match variable for firewall condition.| |
| 60 | +|[New-AzApplicationGatewayFirewallCondition](/powershell/module/az.network/New-AzApplicationGatewayFirewallCondition)|Creates a match condition for custom rule.| |
| 61 | +|[New-AzApplicationGatewayFirewallCustomRule](/powershell/module/az.network/New-AzApplicationGatewayFirewallCustomRule)|Creates a new custom rule for the application gateway firewall policy.| |
| 62 | +|[New-AzApplicationGatewayFirewallPolicy](/powershell/module/az.network/New-AzApplicationGatewayFirewallPolicy)|Creates a application gateway firewall policy.| |
| 63 | +|[New-AzApplicationGatewayWebApplicationFirewallConfiguration](/powershell/module/az.network/New-AzApplicationGatewayWebApplicationFirewallConfiguration)|Creates a WAF configuration for an application gateway.| |
| 64 | + |
| 65 | +## Next steps |
| 66 | + |
| 67 | +- For more information about WAF custom rules, see [Custom rules for Web Application Firewall](../custom-waf-rules-overview.md) |
| 68 | +- For more information on the Azure PowerShell module, see [Azure PowerShell documentation](/powershell/azure/overview). |
| 69 | +- Additional application gateway PowerShell script samples can be found in the [Azure Application Gateway documentation](../powershell-samples.md). |
0 commit comments