Table of Contents
Windows Defender Firewall is a great feature in modern Windows versions. You may have an app (e.g., a local FTP server) which requires a port(s) to be open so other computers on your network can connect to it.
Open a port using netsh command
1. Open an elevated Command Prompt or PowerShell window.

2. Modify the appropriate values to match your app, e.g. the port number, the rule name, the protocol (TCP or UDP).
netsh advfirewall firewall add rule name="Rule Name" dir=in action=allow protocol=TCP localport=80,443
To delete the rule, execute the command as follows:
netsh advfirewall firewall delete rule name="Rule Name"
Open a port using PowerShell
PowerShell is an advanced form of command prompt. It is extended with a huge set of ready-to-use cmdlets and comes with the ability to use in scenarios. You can use it to open or close a port in Windows 10, 11.
There is a special cmdlet New-NetFirewallRule that can be used to open or block a network port in Windows 10, 11.
Open an elevated PowerShell window then run the following command to open tcp/3389.
New-NetFirewallRule `
-DisplayName 'Rule Name' `
-Profile 'Any' `
-Direction Inbound -Action Allow `
-Protocol TCP `
-LocalPort 3389
PS C:\Windows\system32> New-NetFirewallRule -DisplayName 'Rule Name' -Profile 'Any' -Direction Inbound -Action Allow -Protocol TCP -LocalPort 6624
Name : {94a6669a-bbcf-47a7-b70a-bd6f0695a6a3}
DisplayName : Rule Name
Description :
DisplayGroup :
Group :
Enabled : True
Profile : Any
Platform : {}
Direction : Inbound
Action : Allow
EdgeTraversalPolicy : Block
LooseSourceMapping : False
LocalOnlyMapping : False
Owner :
PrimaryStatus : OK
Status : The rule was parsed successfully from the store. (65536)
EnforcementStatus : NotApplicable
PolicyStoreSource : PersistentStore
PolicyStoreSourceType : Local
RemoteDynamicKeywordAddresses :
You can see the firewall rule has been create in Windows Defender Firewall console.

To delete a firewall rule using PowerShell, execute the following command:
Remove-NetFirewallRule -DisplayName 'Rule Name'