Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a large number of remote IPs to specify in Windows Firewall for a blocking rule. The only way I know to enter them is by labouriously entering them an inbound rule's properties Scope tab.

Is there a more efficient way such as a command line option or, even better, pointing to a text file containing the IPs/IP masks?

I'm on Windows Server 2008

share|improve this question
up vote 5 down vote accepted

Assuming the IP addresses are in a text file called "ip.txt", just do:

for /f %i in (ip.txt) do echo netsh advfirewall firewall add rule name="Block %i" dir=in protocol=any action=block remoteip=%i

In a batch file, be sure to change "%i" to "%%i".

share|improve this answer

Use the RunSynchronous command to add, to modify, or to delete Windows Firewall rules.

You can also use an Unattend.xml with the Networking-MPSSVC-Svc component.

More information on technet here

share|improve this answer

You should be able to use the netsh command to add/remove firewall rules via the command line. You can also use a batch for loop to pull the IP addresses from a file.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.