Powershell help please - Adding to a Firewall rule

Commissario
Joined
16 Oct 2002
Posts
342,965
Location
In the radio shack
Hi folks,

I have a firewall rule set in Windows Firewall to block some external IPs and I'd like to add a number of ranges.

I'm using the script as described here.

Code:
$csv = Import-Csv -Path 'C:\Scripts\test.csv'
$data = @()
$csv | ForEach-Object { $data += $_.From + "-" + $_.To }
Set-NetFirewallRule -Name "{6929A9BF-26E7-47D9-BF8B-4602AFE7F489}" -RemoteAddress $data

I wanted to run it on a few IPs first, just to make sure it works before I add loads.

My test.csv file looks like this:

Code:
From,To
1.0.1.0,1.0.1.255
1.0.2.0,1.0.3.255
1.0.8.0,1.0.15.255
1.0.16.0,1.0.31.255


However, when I run the script, it appears to run and finishes with no errors but nothing has been added to the rule. At least, when I check the Scope, nothing has been added.

If I try running the set-netfirewallrule command by itself just to add a single IP, the same happens. It appears to run but nothing is added. I am running Powershell as an administrator.

Running Windows 10. Can anyone suggest what might be wrong please? This looks pretty straightforward but I can't see why it's failing.

Thanks.
 
Thanks for the reply :)

1 - I tried with DisplayName and when it failed, I went with Name and the GUID. Yes, that's the correct one for the rule.
2 - Yup, the rule exists
3 - Dunno and honestly, I'm not that bothered because Peerblock is doing what I want. I've imported the IP list and job's a good 'un.
4 - Gotcha
 
Back
Top Bottom