Whitelist PowerShell, cmd, remote desktop (some Windows apps) in the firewall

2 min read 28-10-2024
Whitelist PowerShell, cmd, remote desktop (some Windows apps) in the firewall

In today's digital landscape, ensuring the security of your computer while maintaining accessibility to necessary applications is crucial. If you're encountering issues with PowerShell, Command Prompt (CMD), or Remote Desktop services being blocked by Windows Firewall, this article provides a clear step-by-step guide on how to whitelist these applications in the firewall settings.

Understanding the Problem

Many users face challenges with Windows Firewall blocking legitimate applications, hindering their ability to execute scripts or connect remotely. This can occur when the firewall settings are too strict or if the applications are not recognized as safe. The original problem can be summed up simply: I need to allow PowerShell, CMD, and Remote Desktop through the Windows Firewall.

Original Code

Here is a generic PowerShell script that attempts to add the necessary rules to the Windows Firewall:

# PowerShell Script to Add Firewall Rules
New-NetFirewallRule -DisplayName "Allow PowerShell" -Direction Inbound -Program "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -Action Allow
New-NetFirewallRule -DisplayName "Allow CMD" -Direction Inbound -Program "C:\Windows\System32\cmd.exe" -Action Allow
New-NetFirewallRule -DisplayName "Allow Remote Desktop" -Direction Inbound -Protocol TCP -LocalPort 3389 -Action Allow

Whitelisting Applications in Windows Firewall

Step-by-Step Guide

Here's how to whitelist PowerShell, CMD, and Remote Desktop in Windows Firewall:

  1. Open Windows Firewall Settings:

    • Press Windows + R to open the Run dialog.
    • Type wf.msc and hit Enter to open Windows Firewall with Advanced Security.
  2. Creating New Inbound Rules:

    • Click on "Inbound Rules" in the left pane.
    • Select "New Rule..." from the right pane.
  3. Allowing Programs:

    • Choose "Program" and click Next.
    • Specify the path of the executable files:
      • For PowerShell: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
      • For CMD: C:\Windows\System32\cmd.exe
    • Click Next.
  4. Action:

    • Choose "Allow the connection" and click Next.
  5. Profile:

    • Select the profiles where you want to apply this rule (Domain, Private, Public) depending on your network configuration.
    • Click Next.
  6. Name the Rule:

    • Give your rule a meaningful name (e.g., "Allow PowerShell", "Allow CMD") and click Finish.
  7. Adding Remote Desktop:

    • For Remote Desktop, repeat steps 2 to 6 but instead of specifying a program, choose "Port" in Step 3, and enter 3389 as the specific port for TCP.

Practical Example

Let’s say you are a developer who frequently uses PowerShell scripts to automate tasks, but the firewall is blocking your scripts from executing. By following the steps above and adding PowerShell to the firewall's whitelist, you can run your scripts without interruption. Similarly, if you are trying to access your work computer remotely using Remote Desktop and it’s not connecting, whitelisting Remote Desktop will allow you to establish a secure connection.

Conclusion

Whitelisting applications such as PowerShell, CMD, and Remote Desktop in Windows Firewall is essential for maintaining productivity and ensuring that you can execute your tasks without unnecessary disruptions. By following the steps outlined in this guide, you can ensure that these important applications are not blocked by the firewall.

Useful Resources

By using this guide, you can enhance both the security and functionality of your Windows environment, ensuring you have access to the tools you need.