I recently came across an issue where I wasn’t sure if a specific set of ports were explicitly opened by the Windows Firewall. As far as I could find there is not a simple method to display this in Windows.
After doing some digging I came up with a couple of PowerShell commands that queries the Windows Firewall to see which ports are opened by the firewall rules.
To list all ports opened by Windows Firewall rules execute the following in PowerShell:
$fw = New-Object -ComObject HNetCfg.FWPolicy2
$fw.Rules | where {$_.Enabled -like $true} | Format-Table LocalPorts
Find if a specific port is open in Windows Firewall and the rule that opens it via Powershell:
$port = 808
$fw = New-Object -ComObject HNetCfg.FWPolicy2
$fw.Rules | where {$_.Enabled -like $true -and $_.LocalPorts -eq $port}