How can I use netsh to find a rule using a pattern
In PowerShell run:
$fw=New-object -comObject HNetCfg.FwPolicy2
$fw.rules | findstr /i "whaturlookingfor"
better yet:
$fw.rules | select name | select-string "sql"
This is best I could do. Anyone know how to take it further? Like remove/subtract the Rule Name from the results?
netsh advfirewall firewall show rule name=all | find "Rule Name:" | find "NameLookingFor"
On Windows 10 I get a warning when I execute netsh advfirewall
, saying that future Windows versions may not support that feature anymore and one should use PowerShell instead. Luckily, what the OP wanted to do is easy in PowerShell:
Get-NetFirewallRule -DisplayName "SQL*"
I had 1000+ firewall rules that were created by a randomly-named executable that I wanted to remove. The following command made this easy to do:
Remove-NetFirewallRule -DisplayName "*mongod.exe"
You can try Select-String:
netsh advfirewall firewall show rule name=all | select-string -pattern "Hyper-V"
Without PowerShell you can simply use regex with findstr:
netsh advfirewall firewall show rule name=all | findstr /R "sql.*"