'How to add IPs scope to existing firewall rule

I want to add a set of IPs to several rules of my firewall that meet the following conditions:

  • They are enabled
  • Inbound rules
  • Contain IP 4.7.5.6

With the following script I managed to add the new IPs but delete the existing IPs in the rule

Get-NetFirewallRule | where {$_.Enabled -eq 'true' -and $_.Direction -eq 'inbound'}  | Get-NetFirewallAddressFilter | Where-Object -FilterScript { $_.RemoteAddress -contains "4.7.5.6" } | set-NetFirewallAddressFilter -RemoteAddress 4.7.5.6,1.1.1.1,2.2.2.2.2,3.3.3.3

Thanks!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source