Log inRegister

Export/Import separate Firewall rules through Powershell

Source: https://gallery.technet.microsoft.com/scriptcenter/Powershell-to-export-and-23287694/view/Reviews

See attached scripts: Export-FirewallRules.ps1 & Import-FirewallRules.ps1.

As with registry actions, first take a backup (on both source and target machine!). You can backup/export the complete Firewall set as follows:
  • right-click the top most item in the TOC of the Firewall (= Windows Defender Firewall with Advanced Security on Local Computer)
  • choose Export Policy…
  • save the .wfw file (e.g. AllFirewallRulesMachineName.wfw)
If necessary, activate the execution policy in Powershell (run as Administrator):
set-executionpolicy unrestricted

Export the desired rule(s). The export script can take three parameters:
  • -Name: display name of the rule(s) to be processed - wildcard * can be used - default is *
  • -CSVFile: output file - default is FirewallRules.csv
  • -JSON: use JSON instead of CSV (default is $FALSE)
.\Export-FirewallRules.ps1 '*Remote*' RemoteRules.json -json

If you want to limit the rules to be imported, simply edit the .csv or .json file.

The import script takes two parameters:
  • -CSVFile: input file - default is FirewallRules.csv
  • -JSON: use JSON instead of CSV (default is $FALSE)
Import the rule(s) as follows:

.\Import-FirewallRules.ps1 RemoteRules.json -json
This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Foswiki? Send feedback