Configure and use Windows 10 Firewall from PowerShell

As part of the set of functions and tools related to security, in addition to the antivirus, Windows has a very advanced firewall. This will be of great help to us to protect our connections and it is also very easy to use.

To begin with, we will tell you that from the Configuration application of the operating system itself we have access to this element. We only have to open the application that we are commenting on through the Win + I key combination.

Open the Windows Firewall GUI

Next, we go to the Update and security section. In the left panel we click on Windows Security to finally click on the Open Window security button.

At that time we fully entered into everything related to the antivirus that is part of this operating system, Windows Defender . But at the same time in this window we find a section called Firewall and network protection. From that moment on, we will be able to control all the functions that this security element offers us in the system.

In the same way, we find a good number of parameters that we can customize and configure. This will help us to have a firewall that works as we wish while using our PC connected to the internet.

interfaz firewall

But this is not the only way we can interact with this element. Perhaps more advanced users of the operating system are interested in knowing that using PowerShell this Firewall can be easily configured from the command line. Precisely below we are going to show you the most common commands used for these tasks with the Windows Firewall .

Use Firewall from PowerShell

The first thing we should know In this sense is that Windows incorporates a module called NetSecurity. This is offered by Microsoft and contains all the necessary functionality to add, remove and modify Firewall rules. In order to use all these commands that we are talking about, the first thing to do is open the PowerShell. We do this by simply typing your name in the Windows 10 search box.

List the rules available for this security element

From that moment on, the window belonging to this element of the system will open.

To load the NetSecurity module as such, we simply have to import it as we will see below:

Import-Module -Name 'NetSecurity'

Once we have loaded the module that we need in the operating system, we are going to obtain a list with the firewall rules that we have at our disposal. We must bear in mind that there are many that we can use, that will depend on the needs of each one or how much we want to delve into this topic.

To see all the existing Firewall rules on the screen, we will do so through the following command:

cmdlet, Get-NetFirewallRule

However, as we mentioned, there are many that we can use, but if, for example, we want to see only the first 10 and have them displayed on the screen, this is how we do it:

Get-NetFirewallRule | Select-Object DisplayName, Enabled, Direction, Action -First 10

listado reglas

Create a new rule for the Firewall

Likewise, it may be the case that we need to create a new and personalized rule. This is something that will be very helpful for users who want to protect their Windows computer as much as possible. Say there are many different ways to create a new rule for this Firewall from the PowerShell. But the command that does it is the following:


We must also bear in mind that for this to work correctly there are some basic properties that we must add. Among the most important, these are some of the ones that you must use almost obligatorily:

  • DisplayName: refers to the custom name of the new Firewall rule.
  • Direction: URL from which we want to block the traffic that comes out of the computer or the one that reaches us.
  • Action: the action to be taken if the rule is met, that is, Allow or Block , so we use the Allow and Block parameters.

Modify an existing rule

It can also be the case that we need or want to modify an existing rule without deleting and recreating it completely. Say that this is something that we can also carry out directly from Windows PowerShell. For this we must execute the following command:


As we told you, this will allow us to modify the firewall rule that we specify in the command itself. Of course, we must bear in mind that as it happened in the creation, here we must use the same parameters that we told you before, that is, DisplayName, Direction and Action. These will help us to establish the new behavior of the rule that we had created at the time.

In addition, it is interesting to know that this same command that we comment on here, has the ability to operate on multiple rules at the same time.

Delete an existing Firewall rule

Finally, we are going to see how to delete an existing rule that is part of the Windows Firewall. We can make this decision in the event that it is no longer necessary to be available in the system. As you can imagine this, we can also do it from PowerShell through a command. Therefore, we only have to open a new window in this section of the system and use the following command that we mention:


All we have to do here is specify the actual name of the existing rule. The thing to keep in mind here is that when using this particular command , it is often advisable to use the following parameter:


It is worth mentioning that this parameter that we are commenting on will be very useful to verify that the rule we refer to here is the correct one before eliminating it completely. At the same time, it is important to point out that thanks to this delete command we have the possibility of deleting several rules at the same time. However, we also recommend that you use it carefully. The main reason for this is that we can make mistakes and delete rules by mistake.

We will also tell you that a useful but dangerous command is the one that helps us eliminate all the Firewall rules that have been created previously: