enira.net

We are all living in a technological wasteland.

RSS
people

Powershell – Windows Firewall: Trusting range of IPs

Introduction

just a code snippet this time. For a demo environment I’ve had to trust an entire set of IPs. Being the lazy person that I am I created a little powershell to add all at once.

The code

$IPs = @("10.10.10.210", "10.10.10.211", "10.10.10.212", "10.10.10.213", "10.10.10.214", "10.10.10.215", "10.10.10.216", "10.10.10.217", "10.10.10.218", "10.10.10.219") |`
	Foreach-object {
 
	#delete old rule (if there is one)
	netsh advfirewall firewall delete rule name="Allow from $_"
	#add new rule 
	netsh advfirewall firewall add rule name="Allow from $_" dir=in action=allow protocol=ANY remoteip=$_
	write-host "$_ Added Incoming for $?"
 
	#delete old rule (if there is one)
	netsh advfirewall firewall delete rule name="Allow to $_"
	#add new rule 
	netsh advfirewall firewall add rule name="Allow to $_" dir=out action=allow protocol=ANY remoteip=$_
	write-host "$_ Added Outgoing $?"
}

Leave a Reply

You must be logged in to post a comment.