Powershell scripts to export and import firewall rules

Powershell scripts to export and import firewall rules in CSV or JSON format. Now here: https://github.com/MScholtes/TechNet-Gallery

 
 
 
 
 
4 Star
(4)
3,011 times
Add to favorites
Networking
5/6/2020
E-mail Twitter del.icio.us Digg Facebook
  • Add parameter for rule direction or store?
    3 Posts | Last post February 17, 2020
    • Hello - Just one suggestion, add parameters so that users can limit the scope of import/export/delete. The export script is really slow so far in my testing, so I think limiting the scope is helpful.
      
      For example I am only interested in working on the active, local inbound rules for my export. So I changed the export with this code:
      
      $FirewallRules = Get-NetFirewallRule -DisplayName $Name -PolicyStore "PersistentStore" | Where-Object { $_.Direction -eq "Inbound" -and $_.Enabled -eq $true } 
      
      This script is awesome though, saved me a lot of time coding! Thanks
    • Hello jstump1,
      
      I have to admit I never looked at the performance of the scripts. I will make some tests and then advance them.
      
      Greetings
      
      Markus
    • Hello jstump1,
      
      just released a new version of the scripts with your suggestions implemented in the export script.
      
      Greeting
      
      Markus
  • Export to object and then import from object
    2 Posts | Last post July 20, 2018
    • 1. Is it possible to use just export to object Get-NetFirewallRule and then import via New-NetFirewallRule?
      2. And serialize object between?
    • Hello Denis,
      
      if it was possible to just export from Get-NetFirewallRule there would be no need for my script. Firewall rules in Powershell are not single objects, they are objects with dependencies to other objects (e.g. address filters, port filters or security filters). On just exporting with Get-NetFirewallRule and importing with New-NetFirewallRule you would loose those settings.
      
      Greetings
      
      Markus