哪个命令列出系统上的所有防火墙规则,输出包含信息和 headers:规则名称、TCP 端口、已启用?

which command that lists all the firewall rules on a system with the output containing the information and headers : Rule name, TCP port, Enabled?

我一直试图从 powershell 的防火墙规则中获取特定数据。我尝试的命令是 Get-NetFirewallRule | select DisplayName, Enabled,但没有输出所需的。

这样试试(有点慢):

$rules = Get-NetFirewallRule
$rules | Foreach {
    $rule = (Get-NetFirewallRule -DisplayName $_.DisplayName | Get-NetFirewallPortFilter)
    If($rule.Protocol -eq "TCP"){
      [PSCustomObject]@{
        'Rule Name' = $_.DisplayName
        'TCP Port' = $rule.LocalPort
        'Enabled' = $_.Enabled
      }
  }
}