Skip to main content
Code and think

Windows Add a new rule to firewall via PowerShell

In case you want to expose a port on Windows machine you can use the following command:

 New-NetFirewallRule -DisplayName 'My port' -Profile 'Private' -Direction Inbound -Action Allow -Protocol TCP -LocalPort 80

You should, of course, adjust the name and the port that you are operating with.

To get a rule by name or display name use:

Get-NetFirewallRule -DisplayName "My port"

And to remove it:

Remove-NetFirewallRule -DisplayName "My port"

Reference