PowerShell 7.3 - implementing Retrieving Windows Firewall Rules Based on Complex Criteria
Quick question that's been bugging me - I'm trying to retrieve specific Windows Firewall rules using PowerShell 7.3, but I'm running into issues filtering the results based on complex criteria..... I need to get all rules that are enabled, belong to a specific group, and allow traffic on certain ports (for example, TCP ports 80 and 443). Here's what I have so far: ```powershell # Retrieve all rules $firewallRules = Get-NetFirewallRule | Where-Object { $_.Enabled -eq 'True' } # Attempting to filter by group and local ports $filteredRules = $firewallRules | Where-Object { $_.Group -eq 'MyCustomGroup' -and ($_.Action -eq 'Allow' -and ($_.LocalPort -eq '80' -or $_.LocalPort -eq '443')) } ``` However, I keep getting the following behavior message when I try to access the `LocalPort` property: ``` Get-NetFirewallRule : The property 'LocalPort' want to be found on this object. ``` It seems like not all firewall rules have a `LocalPort` property, and I suspect that I might need to access the associated `NetFirewallPortFilter` objects to get the ports. I've also tried using `Get-NetFirewallPortFilter` but I'm unsure how to correlate those with my current firewall rules. Any suggestions on how to properly filter these rules based on the criteria I've outlined? I've also read some documentation but couldn't find any clear examples on how to handle this scenario. Any help would be greatly appreciated! My development environment is macOS. Thanks in advance! I'd really appreciate any guidance on this.