Issue Importing multiple IP's into firewall via NETSH

I am attempting to create a PowerShell script to add ip addresses to an existing Firewall rule. When I run the following only the last entry is ever added to the firewall rule.

$IPs = @("159.55.107.71", "159.55.110.45", "10.38.82.183", "10.208.165.147", "10.241.186.232", "10.241.186.234", "10.17.98.232", 
"10.211.106.92", "10.208.96.181", "10.208.35.191") |`
   Foreach-object {
   netsh advfirewall firewall set rule name="Existing Firewall Rule" new remoteip="$_"
   write-host "$_ Added $?"
}

When the script completes it shows that it has added every ip but when I check the rule I only see the last ip address in the script.

I have tried removing the brackets and spaces and adding /32 to the end and none of those options worked to add the range.

Hopefully someone can point me in the direction of where I went wrong.

August 20th, 2015 2:43pm

Hi,

According to your description, my understanding is that you want to add IP addresses to an existing Firewall rule using PowerShell script.

Your question is mainly about PowerShell script, so I have moved this post to PowerShell forum so that you would get more professional support.

Best Regards,
Eve Wang
Free Windows Admin Tool Kit Click here and download it now
August 21st, 2015 11:35pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics