How to create a Windows 2008 Advanced Firewall rules group definition through the command prompt

Is there a way to create a group, or add to an existing group, to a rule in Windows Advanced Firewall (preferable through a command prompt or WSH script).

Edit:

enter image description here


Solution 1:

Found a solution for this old question that has also been bugging me for a long time!

The New-NetFirewallRule TechNet article states this about the -Group parameter of the New-NetFirewallRule commandlet:

[...] This parameter specifies the source string for the DisplayGroup parameter. [...] Rule groups can be used to organize rules by influence and allows batch rule modifications. Using the Set-NetFirewallRule cmdlets, if the group name is specified for a set of rules or sets, then all of the rules or sets in that group receive the same set of modifications. It is a good practice to specify this parameter value with a universal and world-ready indirect @FirewallAPI name.

Note: The DisplayGroup parameter cannot be specified upon object creation using the New-NetFirewallRule cmdlet, but can be modified using dot-notation and the Set-NetFirewallRule cmdlet.

That sounds like there's a chance, right? While trying to find out how to do this myself, I ran the following:

Get-NetFirewallRule -DisplayName "Core Networking - IPv6 (IPv6-In)" | Get-Member

...and noted that the DisplayGroup property only has a Get method, but the Group property (with its RuleGroup alias) has both a Get and a Set method.

The PowerShell solution is as-follows:

Thanks to @maoizm, this solution now works when 1 or more rules with the same DisplayName exist:

$RuleName = "NameOfYourFirewallRuleGoesHere"
$RuleGroup = "YourGroupNameGoesHere"
Get-NetFirewallRule -DisplayName $RuleName | ForEach { $_.Group = '$RuleGroup'; Set-NetFirewallRule -InputObject $_ }

And this will actually create a new group name that is assigned to your rule.

Note: The netsh command does not have an add group command. See the syntax for Netsh AdvFirewall Firewall Commands here.

Solution 2:

Rules in the Windows Firewall can be bundle together and activated or deactivated as a group.

With netsh advfirewall command you can add rules to the Firewall. Use the switch group= for manage the AdvFirewall groups.

Use something like this:

netsh advfirewall firewall set rule profile=domain group="Remote Desktop" new enable=Yes