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

Viewed 155

I have been trying to get only specific data from the firewall rules in powershell. The command i tried is Get-NetFirewallRule | select DisplayName, Enabled, but it does not output required one.

1 Answers

Try like this (It's a bit slow):

$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
      }
  }
}
Related