The New-AzFirewallNetworkRuleCollection cmdlet creates a collection of Firewall Network Rules.
Examples
Example 1: Create a network collection with two rules
$rule1 = New-AzFirewallNetworkRule -Name "all-udp-traffic" -Description "Rule for all UDP traffic" -Protocol UDP -SourceAddress "*" -DestinationAddress "*" -DestinationPort "*"
$rule2 = New-AzFirewallNetworkRule -Name "partial-tcp-rule" -Description "Rule for all TCP traffic from 10.0.0.0 to 60.1.5.0:4040" -Protocol TCP -SourceAddress "10.0.0.0" -DestinationAddress "60.1.5.0" -DestinationPort "4040"
New-AzFirewallNetworkRuleCollection -Name RC1 -Priority 100 -Rule $rule1, $rule2 -ActionType "Allow"
This example creates a collection which will allow all traffic that matches either of the two rules.
The first rule is for all UDP traffic.
The second rule is for TCP traffic from 10.0.0.0 to 60.1.5.0:4040.
If there is another Network rule collection with higher priority (smaller number) which also matches traffic identified in $rule1 or $rule2,
the action of the rule collection with higher priority will take in effect instead.
Example 2: Add a rule to a rule collection
$rule1 = New-AzFirewallNetworkRule -Name "all-udp-traffic" -Description "Rule for all UDP traffic" -Protocol UDP -SourceAddress "*" -DestinationAddress "*" -DestinationPort "*"
$ruleCollection = New-AzFirewallNetworkRuleCollection -Name "MyNetworkRuleCollection" -Priority 100 -Rule $rule1 -ActionType "Allow"
$rule2 = New-AzFirewallNetworkRule -Name "partial-tcp-rule" -Description "Rule for all TCP traffic from 10.0.0.0 to 60.1.5.0:4040" -Protocol TCP -SourceAddress "10.0.0.0" -DestinationAddress "60.1.5.0" -DestinationPort "4040"
$ruleCollection.AddRule($rule2)
This example creates a new network rule collection with one rule and then adds a second rule to the rule collection using method
AddRule on the rule collection object. Each rule name in a given rule collection must have a unique name and is case insensitive.
This example creates a new network rule collection with one rule and then gets the rule by name, calling method GetRuleByName on the
rule collection object. The rule name for method GetRuleByName is case-insensitive.
Example 4: Remove a rule from a rule collection
$rule1 = New-AzFirewallNetworkRule -Name "all-udp-traffic" -Description "Rule for all UDP traffic" -Protocol UDP -SourceAddress "*" -DestinationAddress "*" -DestinationPort "*"
$rule2 = New-AzFirewallNetworkRule -Name "partial-tcp-rule" -Description "Rule for all TCP traffic from 10.0.0.0 to 60.1.5.0:4040" -Protocol TCP -SourceAddress "10.0.0.0" -DestinationAddress "60.1.5.0" -DestinationPort "4040"
$ruleCollection = New-AzFirewallNetworkRuleCollection -Name "MyNetworkRuleCollection" -Priority 100 -Rule $rule1, $rule2 -ActionType "Allow"
$ruleCollection.RemoveRuleByName("ALL-udp-traffic")
This example creates a new network rule collection with two rules and then removes the first rule from the rule collection by calling method
RemoveRuleByName on the rule collection object. The rule name for method RemoveRuleByName is case-insensitive.
Parameters
-AcquirePolicyToken
Acquire an Azure Policy token automatically for this resource operation.
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable,
-InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable,
-ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see
about_CommonParameters.
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.