Network

List & Add Windows Firewall Rules with PowerShell

3 min · updated June 14, 2026

The NetSecurity module manages Windows Firewall. Adding/changing rules needs an elevated prompt.

List enabled inbound rules

Get-NetFirewallRule -Direction Inbound -Enabled True |
  Select-Object DisplayName, Action, Profile

Find the rule(s) for a port

Get-NetFirewallPortFilter | Where-Object LocalPort -eq 3389 |
  Get-NetFirewallRule | Select-Object DisplayName, Direction, Action, Enabled

Add an inbound allow rule (admin)

New-NetFirewallRule -DisplayName "Allow App 8080" -Direction Inbound `
  -LocalPort 8080 -Protocol TCP -Action Allow -Profile Domain,Private

Disable / enable / remove a rule (admin)

Disable-NetFirewallRule -DisplayName "Allow App 8080"
Enable-NetFirewallRule  -DisplayName "Allow App 8080"
Remove-NetFirewallRule  -DisplayName "Allow App 8080"

Is the firewall on per profile?

Get-NetFirewallProfile | Select-Object Name, Enabled

Notes: scope new rules with -Profile (Domain/Private/Public) so you don’t accidentally open a port on untrusted networks. The backtick (`) at line ends is PowerShell’s line-continuation — or put the whole New-NetFirewallRule on one line. Removing a rule is immediate and has no undo; disable first if you’re unsure.

← All recipes