Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm wondering whether anyone in Microsoft has ever come to a situation where they can't remember a rule's name!
The netsh advfirewall firewall show rule only accepts 1 name and no pattern matching facility is available on netsh to help find a rule using a pattern like "SQL*" or ^SQL.+$
using show and name=all it is possible to list all rules but I was unable to find a solid command-line grep tool for windows.

I want to be able to run a command like this:

netsh advfirewall firewall show rule name=sql*

Is this possible?

share|improve this question
    
a fast answer would be: netsh advfirewall firewall show rule name=all | find "SQL"; but the output and the control is not as satisfying as it should be. It's rather messy and even worse, Case-Sensitive ... –  Achilles Aug 8 '12 at 16:46
    
think the following link may help blogs.technet.com/b/jamesone/archive/2009/02/18/… –  tony roth Aug 8 '12 at 16:54
    
Using Powershell is another option; yes. but what if you want to do this on a remote machine? Is it possible to leave the remote ports for PS open and have IDS/IPS like what I have with BvSsshServer? I'm looking for something available in Windows' native command prompt. –  Achilles Aug 9 '12 at 5:43
    
It seems like it's possible to secure PS using SSL: technet.microsoft.com/en-us/magazine/ff700227.aspx –  Achilles Aug 9 '12 at 5:49
    
I've found that using /I with FIND command, I can dodge the case-sensitive problem; but the result is still messy... –  Achilles Aug 11 '12 at 8:07
show 1 more comment

3 Answers

to simplify.

$fw=New-object -comObject HNetCfg.FwPolicy2    
$fw.rules | findstr /i "whaturlookingfor"

better yet

$fw.rules | select name | select-string "sql"
share|improve this answer
    
Thanks. This is the best answer till now :) –  Achilles Aug 11 '12 at 8:08
    
$fw.rules | where-object {$_.Enabled -eq $true -and $_.Direction -eq 1} Helped me arrive at this (inbound enabled). –  Bratch Jan 21 at 20:11
add comment

You can try Select-String:

netsh advfirewall firewall show rule name=all | select-string -pattern "Hyper-V"
share|improve this answer
add comment

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"
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.