guide · static export
Security · firewall

Export and Restore Your Windows Firewall Rules

The firewall is the part of a rebuild nobody remembers until a game server or a dev tool stops working. One file holds every rule, and one command puts them all back.

by@guidox updated:10/31/26 time:25 min level:Intermediate tested on:Windows 11 24H2 works on:Windows 10, Windows 11, Windows Server 2019 tools:Command Prompt as administrator
TL;DR

Export the whole policy with **netsh advfirewall export**, keep a readable copy of the rules from **Get-NetFirewallRule**, and restore with **netsh advfirewall import** — which replaces every rule in the store.

Before you start

Requirements

  • Admin rights
  • A folder for the exports
  • 25 minutes
Step by step

Instructions

01

Record the profile state first

The rules mean nothing without the **profile** settings they run under. Capture which profile is active and how it treats inbound traffic by default.

Get-NetFirewallProfile | Select-Object Name,Enabled,DefaultInboundAction,DefaultOutboundAction,NotifyOnListen
02

Export the binary policy

**netsh advfirewall export** writes one file containing every rule and every profile setting. This is the file to restore after a reinstall.

New-Item -ItemType Directory C:\FwBackup -Force | Out-Null
netsh advfirewall export "C:\FwBackup\rules.wfw"
Get-ChildItem C:\FwBackup | Select-Object Name,Length
03

Keep a readable copy as well

A .wfw file is binary and cannot be diffed. The CSV export shows what each rule does, which is what you need when two machines disagree.

Get-NetFirewallRule |
  Select-Object DisplayName,Direction,Action,Enabled,Profile |
  Export-Csv C:\FwBackup\rules.csv -NoTypeInformation -Encoding UTF8
netsh advfirewall firewall show rule name=all > C:\FwBackup\rules.txt
04

Restore the file on the new installation

**import** replaces the entire rule store with the content of the file. Rules created after the export are gone, including the ones setup added for new applications.

netsh advfirewall import "C:\FwBackup\rules.wfw"
Get-NetFirewallProfile | Select-Object Name,Enabled
⚠ warningImport on a machine that has been running for months, and you silently remove every rule added since the export. Compare the CSV before you do it.
05

Recreate a single rule from the CSV

For one missing rule the export is overkill. Rebuild it explicitly so its scope and profile are visible in the command you ran.

New-NetFirewallRule -DisplayName 'Dev Server 8080' -Direction Inbound -Protocol TCP -LocalPort 8080 -Action Allow -Profile Private
Get-NetFirewallRule -DisplayName 'Dev Server 8080' | Select-Object DisplayName,Enabled,Direction,Action,Profile
06

Verify the result instead of trusting the import

Count the rules and test a port that should be reachable. A rule can exist and still be disabled, blocked by a policy or bound to the wrong profile.

(Get-NetFirewallRule).Count
Get-NetFirewallRule -Enabled True | Where-Object Direction -eq 'Inbound' | Measure-Object | Select-Object Count
Test-NetConnection -ComputerName 127.0.0.1 -Port 8080 -InformationLevel Quiet
Troubleshooting

Common issues

The import reports success but nothing works

The active network profile changed. Rules scoped to Private do not apply when Windows classifies the network as Public — check Get-NetConnectionProfile.

Import fails with access denied

The firewall service or a policy is blocking it. Run the prompt elevated, and check whether a domain policy owns the store.

A third-party security suite replaced the firewall

Its own ruleset is in charge. The Windows rules stay dormant until that product is removed, which is why the import appears to do nothing.

Rules keep disappearing

A security tool or a policy cleans them. Compare the CSV against the current list hourly to find the pattern.

FAQ

Frequently asked

Can I move the rule file to another PC?

Yes, the format is machine-neutral. Interface-specific and program-path-specific rules need review because the paths differ.

Is a reset faster than restoring?

**netsh advfirewall reset** gives you a clean default state. Restoring is for keeping a curated set of rules, not for fixing a broken one.

How to undo this

Restore the previous .wfw file with netsh advfirewall import, or reset the store with netsh advfirewall reset and recreate the rules you still need from the CSV.

Changelog · 1 entry
  1. 2026-10-31
    First version
Interactive version: checklist, feedback, related guides →

Free · no account needed · tracks your progress