Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

On Windows XP and Windows Server 2003, I can know currently open ports on the Windows Firewall using the following command:

netsh firewall show state

However, on Windows 7 and Hyper-V Server 2008 R2, when I give that command, it says:

No ports are currently open on all network interfaces.

IMPORTANT: Command executed successfully.
However, "netsh firewall" is deprecated;
use "netsh advfirewall firewall" instead.

Apparently there are ports open because services such as NetBIOS NS, Remote Desktop, and Hyper-V remote administration are functioning.

I tried a few 'netsh advfirewall' show commands, but didn't get a way to find out which ports are permit by Windows Firewall.

Knowing the currently open ports, I can be sure that I'm permitting necessary and sufficient traffic to pass in, no more, no less.

Going through the whole set of advanced firewall rules is so tedious and error-prone.

Is there a command on Windows 7 and Windows Server 2008 to do this efficiently?

share|improve this question
How is it error prone? – joeqwerty Jan 11 '11 at 12:03
There are so many rules while I'm just interested in the effective ones. – QIU Quan Jan 11 '11 at 12:06
And that makes it error prone? – joeqwerty Jan 11 '11 at 12:07
Yeah. Examining dozens of rules in a second is error prone. – QIU Quan Jan 11 '11 at 12:18
Prone to what errors exactly? Reading them wrong? Why are you trying to read them in one second? Try slowing down a little bit. In addition, in the GUI you can filter the view by the state of the rule, so you could filter it to show only those rules that are enabled. – joeqwerty Jan 11 '11 at 12:26
up vote 1 down vote accepted

The reason you can't get the same results using the same commands is that the Win7 firewall rules can be specific to an individual application, and configured per network type (Private, Domain, Public), protocol, port, etc. Powershell should give you a much better way to query this information and sort it. Here's a quick script I have to dump my configuration, when I need it.

Function Get-EnabledRules
    $rules = (New-Object -comObject HNetCfg.FwPolicy2).rules
    $rules = $rules | where-object {$_.Enabled -eq $true}
    $rules = $rules | where-object {$_.Profiles -bAND $profile}

$networkListManager = [Activator]::CreateInstance([Type]::GetTypeFromCLSID([Guid]"{DCB00C01-570F-4A9B-8D69-199FDBA5723B}"))
 $connections = $networkListManager.GetNetworkConnections()
[int[] ] $connTypes = @()
$connTypes = ($connections | % {$_.GetNetwork().GetCategory()})
#$connTypes += 1
Write-Host $connTypes

$connTypes | ForEach-Object {Get-EnabledRules -profile $_ | sort localports,Protocol | format-table -wrap -autosize -property Name, @{Label="Action"; expression={$_.action}}, @{Label="Protocol"; expression={$_.protocol}}, localPorts,applicationname}

A lot of this was based off of this post on MSDN

share|improve this answer
Great! It really works. Thanks! – QIU Quan Jan 13 '11 at 6:30

This is old, but people may wish to know that you can do this with "netstat". The command has been available in out-of-the-box Windows for a really, really long time.

For example, get to an elevated command prompt and use netstat -a -b. Among other things, it lists every bound port on the machine and (attempts) to show you the process that owns it.

share|improve this answer

Your Answer


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.