In this post I will show you how you can export/import Windows Firewall rules using PowerShell.
How to Export/Import firewall rules
Sometime you might have a task, where you have to move software from one server to another, but it is not just always about moving file. You might also need to move firewall rules. If there are many rules, you might want to script your solution, to make sure that you don’t miss important details. In this post I will show you have you can export/import firewall rules, using some simple PowerShell cmd-lets.
Installing module Firewall Manager
Before we can start exporting firewall rules, we need to install the PowerShell module for Windows Firewall, that we will need for this task. The name of the module is Firewall-Manager. In order to install the module, you should run the following command from a PowerShell prompt:
Export Firewall Rule with PowerShell
Now we are ready to export a rule from a source server. For that we will use a cmd-let from the module we just imported named Export-FirewallRules. In the example below I will restore the firewall rule named DropBox:
Import Firewall Rule with PowerShell
Now where we have a csv file with Firewall rules we just exported, we are ready to go ahead and import the csv file on the target server.
Export Multiple Firewall rules
If you need to export multiple rules that is also possible using wildcard (*). E.g. if you want to export all rules starting with Microsoft you can use the following command:
All the above examples are all with the -Inbound parameter. If you need to import and export outbound firewall rules you just use the -Outbound parameter instead.
More information about Export-FirewallRules
I hope you found this post useful. Feel free to drop me a comment or question below. For more information you can check out the Firewall-Manager project on GitHub here