0

I am aiming to list all available firewall rules by given filters and quite new to Powershell.

Observed a strange behavior which led me asking if there is something hidden that I am not aware of. I may use Pipes to accomplish the same, but I am interested in the reason to understand if there is something that.

Get-NetFirewallRule -DisplayGroup n*

functions as expected

Get-NetFirewallRule -DisplayName n*

functions as expected

But when I am adding/combining -Enabled True the DisplayName is generating such an error message where DisplayGroup is generating a result.

Parameter set cannot be resolved using the specified named parameters.

  • Get-NetFirewallRule -DisplayName n* -Enabled True
Get-NetFirewallRule -Enabled True | ? DisplayName -like nsc*

is working

PS Version '5.1.177' on a Windows 10 Machine.

phuclv
  • 37,963
  • 15
  • 156
  • 475
Ali Avcı
  • 870
  • 5
  • 8
  • 2
    If you look at [the docs](https://docs.microsoft.com/powershell/module/netsecurity/get-netfirewallrule?view=windowsserver2019-ps) you will see several different parameter sets; none allow *both* `DisplayName` and `Enabled`. As to why not, that would be a question for the developer of the cmdlet; PowerShell doesn't mandate this. I would suggest inverting the logic, incidentally -- fetch rules matching the name, then filter by enabled status, as it's likely the former set is smaller than the latter and/or has a built-in native filter and thus gives better performance on large rule sets. – Jeroen Mostert May 31 '21 at 09:50
  • Got the point. Thank you for the clarification. When reading documentation about PS I'll take that information about parameter sets into consideration. – Ali Avcı Jun 05 '21 at 19:52

1 Answers1

0

This should work:

Get-NetFirewallRule | ? {($_.DisplayName -like "nsc*") -and ($_.Enabled -eq $true)}
phuclv
  • 37,963
  • 15
  • 156
  • 475
alexzelaya
  • 255
  • 1
  • 7