New-NetFirewallRule TechNet文章说明了有关New-NetFirewallRule命令行开关的-Group参数:
[…] 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.
听起来有机会,对吧?在尝试了解如何自己完成此操作时,我运行了以下内容:
Get-NetFirewallRule -DisplayName "Core Networking - IPv6 (IPv6-In)" | Get-Member
…并注意到DisplayGroup属性只有Get方法,但Group属性(带有RuleGroup别名)同时具有Get和Set方法.
PowerShell解决方案如下:
感谢@maoizm,此解决方案现在可用于存在一个或多个具有相同DisplayName的规则:
$RuleName = "NameOfYourFirewallRuleGoesHere" $RuleGroup = "YourGroupNameGoesHere" Get-NetFirewallRule -DisplayName $RuleName | ForEach { $_.Group = '$RuleGroup'; Set-NetFirewallRule -InputObject $_ }
这实际上会创建一个分配给您的规则的新组名.
注意:netsh命令没有add group命令.请在此处查看Netsh AdvFirewall Firewall Commands的语法.