How to determine Windows firewall rule’s program path using Powershell Get-NetFirewallRule

Question:

We define a new Windows firewall rule for some program to accept inbound TCP connections on some port. This can be done using either netsh.exe utility or Powershell New-NetFirewallRule cmdlet. For a example, here’s a sample command to allow notepad.exe to accept TCP connections on port 5001 (I know, notepad can’t do that):

To retrieve/view this rule, one can again use netsh.exe or Get-NetFirewallRule cmdlet.

Ideally we’d like to use Powershell Get-NetFirewallRule, but we are not able to view the actual program path that was used when the rule was created.

Here’s the output of netsh.exe:

Here’s the output of Get-NetFirewallRule cmdlet:

Any suggestions or ideas on retrieving program path, port, protocol, etc., using Powershell cmdlet?

Answer:

You should use Get-NetFirewall*Filter cmdlets for this.

All of that cmdlets have -AssociatedNetFirewallRule parameter, which accepts pipeline input.

In your case, you can use following command:

Source:

How to determine Windows firewall rule’s program path using Powershell Get-NetFirewallRule by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply