加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

如何通过命令提示符创建Windows 2008 Advanced Firewall规则组定

发布时间:2020-12-14 00:06:32 所属栏目:Windows 来源:网络整理
导读:有没有办法在 Windows高级防火墙中创建组或添加到现有组的规则(最好通过命令提示符或WSH脚本). 编辑: 找到了这个老问题的解决方案,这个问题一直困扰着我很久! New-NetFirewallRule TechNet文章说明了有关New-NetFirewallRule命令行开关的-Group参数: […]
有没有办法在 Windows高级防火墙中创建组或添加到现有组的规则(最好通过命令提示符或WSH脚本).

编辑:

找到了这个老问题的解决方案,这个问题一直困扰着我很久!

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的语法.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读