Open a firewall port on Windows (New-NetFirewallRule)

Create an inbound allow rule for a TCP/UDP port with one PowerShell cmdlet, and delete it cleanly afterwards.

WindowsportspowershellfirewallMedium risk
Run New-NetFirewallRule -DisplayName "Allow HTTP 8080" -Direction Inbound -Protocol TCP -LocalPort 8080 -Action Allow to open the port.

01Command

Command
$ New-NetFirewallRule -DisplayName "Allow HTTP 8080" -Direction Inbound -Protocol TCP -LocalPort 8080 -Action Allow

02What it does

Unlike reading rules, creating one is the other half of the NetSecurity module and is fully idempotent-safe: you can scope the rule with -RemoteAddress, -Profile (Domain/Private/Public) and -Program so it is far narrower than a GUI rule usually ends up. The undo is Remove-NetFirewallRule by the same DisplayName, or Disable-NetFirewallRule to keep it but turn it off. Rules created this way appear in Windows Defender Firewall with Advanced Security like any other.

03Risk

RiskMedium risk
RequirementsRun PowerShell as Administrator
!Warning: Every open inbound port is attack surface — prefer -Profile scoping and -RemoteAddress limits over a global Allow whenever the service is not meant to be public.

04Undo

Undo
$ Remove-NetFirewallRule -DisplayName "Allow HTTP 8080"

05Sources

  • New-NetFirewallRule | Microsoft Learn
    Microsoft · vendor-doc · 2026-09-17
    Evidence: Microsoft documents New-NetFirewallRule with parameters -Direction, -Protocol, -LocalPort and -Action to create an inbound allow rule.

Last verified: 2026-09-17 · Category: Network

06Related solutions