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

Actually theusers script is perfect for PowerShell. The issue is about how to use a system utility called "NETSH".  What happens when you add a rule by name?  What does NETSH do.  Does it add a value to the name or does it just replace the rule with the current value?

Do you, Eve, know the answer?

Can you look it up?

[remoteip=any|localsubnet|dns|dhcp|wins|defaultgateway|
   <IPv4 address>|<IPv6 address>|<subnet>|<range>|<list>]

So these are the possibilities.

This is not a scripting issue. It is an issue for the platform forum about how to use a system utility.

Oh.  The answer here is "list"

Daniel.  Please forgive out friends in the platform groups (). They are still learning how to use Windows. 

In the future try using the help built into every utility first.  It will save you a lot of

Free Windows Admin Tool Kit Click here and download it now
August 22nd, 2015 3:22am

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

Other recent topics Other recent topics