I have a PowerShell script which adds IP addresses to Windows Firewall using the "netsh advfirewall" command. (As described in this question: How to append netsh firewall rules, not just replace).
The problem is that when adding a lot of IP addresses (currently over 700) the string of IP addresses seems to be 'cut off' at some point. Only an X amount of the total amount of IP addresses are actually added to the firewall, the rest... not.
The script is very simple, and looks something like this:
$ip = "123.123.123.123,124.124.124.124,125.125.125.125 and so on"
netsh advfirewall firewall set rule name="*" new remoteip="$ip"
I tried to echo the string to see if it's cut off;
echo $ip
But the complete string is correctly echo'ed.
Is there some kind of string length limit for the netsh command? Or anything else that could be causing this issue?
Edit
I've done some more research and it appears that the string is not 'cut off'. I've rearranged the IP string in ascending order, and the last IP address of the string was added to the firewall. So I suppose I can conclude that there is not some kind of string limit.
However, random IP's are being omitted. I've written several 'debug' scripts to figure out what is going on, one of those scripts generates a list of IP addresses that are in the IP string (and thus supposed to be in the firewall), but are not present in the firewall. It turns out that it's simply omitting random IP addresses... and I have no clue why...
The IP addresses that are being omitted are perfectly fine IP addresses though (not ranges or anything, just plain normal IP addresses).
Any ideas?