How to Remove Duplicate Windows Firewall Rules

Duplicated rules in Windows Firewall usually don't cause any issues

Reading time icon 4 min. read


Readers help support Windows Report. We may get a commission if you buy through our links. Tooltip Icon

Read our disclosure page to find out how can you help Windows Report sustain the editorial team Read more

Key notes

  • You can delete multiple rules from Windows Firewall manually right from the application.
  • More advanced users can use a PowerShell script to automate the process.

Duplicated Windows Firewall rules can cause confusion, especially if you’re manually configuring your firewall, and in some cases, it can cause certain applications or services to stop working.

It’s possible to fix this issue, and in this guide, we’ll show you a couple of methods that you can use, so let’s get started.

Where are Windows Defender Firewall rules stored?

You can find your firewall rules stored in the following key in your registry at the following path: Software\Policies\Microsoft\WindowsFirewall\FirewallRules

How do I delete duplicate rules in Windows Firewall?

1. Manually delete the rules from firewall settings

Note icon NOTE
Deleting certain rules might lead to network issues, so remove them at your own risk.
  1. Press the Windows key + S and enter defender. Select Windows Defender Firewall with Advanced Security.
     
  2. From the left pane, select Outbound Rules or Inbound Rules.
  3. Select multiple rules by using Shift or Ctrl and the left mouse button.
  4. Once you’ve selected duplicate firewall rules, right-click them and choose Delete.
  5. When asked to confirm, click on Yes.
  6. Repeat these steps for all rules you want to remove.

Instead of deleting rules, it might be a better option to disable them instead. That way if anything goes wrong, you can enable these rules again.

2. Use the script to remove Windows Firewall rules

  1. Open Notepad.
  2. Paste the following code:
    # Here we use `netsh advfirewall firewall show` to get all firewall rules, since it's way faster than Get-NetFirewallRule!!!!!!! $output = (netsh advfirewall firewall show rule name=all verbose | Out-String).Trim() -split '\r?\n\s*\r?\n' $propertyNames = [System.Collections.Generic.List[string]]::new() $objects = @( $(foreach($section in $output ) { $obj = @{} foreach( $line in ($section -split '\r?\n') ) { if( $line -match '^\-+$' ) { continue } $name, $value = $line -split ':\s*', 2 $name = $name -replace " ", "" $obj.$name = $value if($propertyNames -notcontains $name) { $propertyNames.Add( $name ) } } $obj }) | % { foreach( $prop in $propertyNames ) { if( $_.Keys -notcontains $prop ) { $_.$prop = $null } } [PSCustomObject]$_ }) $r = $objects | Group-Object -Property RuleName, Program, Action, Profiles, RemoteIP, RemotePort, LocalIP, LocalPort, Enabled, Protocol, Direction # If you want to take a look # $r | ?{$_.Count -gt 1} | Select-Object -ExpandProperty group | Out-GridView $r | ?{$_.Count -gt 1} | %{ $name = $_ | Select-Object -ExpandProperty group | Select-Object -ExpandProperty RuleName -First 1 # Here we have to use this cmdlet, since `netsh advfirewall firewall delete` can't differentiate rules with the same names and will delte them all! Get-NetFirewallRule -DisplayName $name | Select-Object -Skip 1 | Remove-NetFirewallRule }
  3. Click on File and choose Save as.
     
  4. Set Save as type to All files and set the name of the file to firewall.ps1. Lastly, click Save.
  5. Press Windows key + S and type powershell. Select Run as administrator.
    Powershell Show The Folder Size on Windows 11Show The Folder Size on Windows 11
  6. Switch to the directory where your ps1 file is saved using the cd command like this: cd C:\Users\WindowsReport\Documents
  7. Next, type firewall.ps1, and the script should start and remove duplicate entries.

Keep in mind that this is an advanced solution, so you should use it only if you have some basic knowledge of the PowerShell commands and you understand what the script does.

Tips for cleaning Windows Firewall rules

  • Review the rules before you remove them. Many rules aren’t duplicates, and they are configured to work with different protocols or ports.
  • Instead of deleting, it’s always better to disable a rule and check if any issues appear after doing so.
  • Remove only redundant rules or unused ones.
  • Label and organize rules properly. Arrange rules by priority or functionality.

Duplicate Windows Firewall rules shouldn’t concern you, especially if you didn’t manually create them. Despite looking almost the same, likely, rules aren’t duplicates, so don’t delete them unless you’re 100% certain and you know what the rules in question are doing.

In case you want to learn more about Windows Firewall, you can use it to check if firewall is blocking a port or a program or you can configure Windows Firewall to allow IP ranges on your PC.

Speaking of which, you can even configure firewall rules for Windows activation to ensure that no issues occur during the process.

Have you encountered duplicate Windows Firewall rules on your PC and how did you handle them? Share your findings with us in the comments section.

More about the topics: Windows 11 guides