How to Enable a Port Through PowerShell

Published February 8, 2025
How to Enable a Port Through PowerShell
Cheap Dedicated Server

How to Enable a Port Through PowerShell


Enabling a port through PowerShell is useful for network configurations, troubleshooting, or setting up applications that require specific ports. You can achieve this using the Windows Firewall cmdlets in PowerShell.

Steps to Enable a Port Using PowerShell

  1. Open PowerShell as Administrator
    Press Win + X and select Windows PowerShell (Admin).
  2. Allow Incoming Traffic on a Specific Port
    Run the following command to enable a port (e.g., TCP port 8080):
    blank

     

    New-NetFirewallRule -DisplayName "Allow Port 8080" -Direction Inbound -Action Allow -Protocol TCP -LocalPort 8080
  3. Allow Outgoing Traffic on a Specific Port
    If your application also needs to send data, enable outbound traffic:blank

     

    New-NetFirewallRule -DisplayName "Allow Outbound Port 8080" -Direction Outbound -Action Allow -Protocol TCP -LocalPort 8080
  4. Verify the Firewall Rule
    Check if the rule was added successfully:blank

     

    Get-NetFirewallRule -DisplayName "Allow Port 8080"
  5. Remove a Firewall Rule (If Needed)
    If you need to delete the rule:Remove a Firewall Rule (If Needed)

     

    Remove-NetFirewallRule -DisplayName "Allow Port 8080"

 

 

How to Grant su (Superuser) Access to a User in Ubuntu​ (F.A.Q)

 

How can I enable a UDP port instead of TCP?

Modify the command to use -Protocol UDP, like this:

New-NetFirewallRule -DisplayName "Allow UDP Port 8080" -Direction Inbound -Action Allow -Protocol UDP -LocalPort 8080

How do I check if a port is open?

Use the following command:

Test-NetConnection -ComputerName localhost -Port 8080

Can I enable multiple ports at once?

Yes, separate ports with commas:

New-NetFirewallRule -DisplayName "Allow Multiple Ports" -Direction Inbound -Action Allow -Protocol TCP -LocalPort 8080, 9090, 443

Do I need to restart my computer for the changes to take effect?

No, firewall rules take effect immediately.