Solved

Powershell Script Modification

Posted on 2015-02-05
3
147 Views
Last Modified: 2015-02-05
# get ip addresses that are not already in firewall rule.
$w = $g | where {$_.Name.Length -gt 1 -and  !($arRemote -contains $_.Name + '/255.255.255.255')} 

# add IPs to firewall rule
$w| %{$ar.remoteaddresses += ',' + $_.Name} 

Open in new window


I have the above code as part of a scrip that automatically grabs and logs IPs into a Block Rule on a Windows Server.   This script is deployed across multiple servers, but one client is having a problem where their internal IPs are being blocked by some users with drives mapped via VPN.

I've unsuccessfully attempted to add to this, so maybe an Expert can help -- I'd like to tack on an exception to the criteria to skip all IPs on the internal subnet (in this case, 192.168.125.0/24 ).  Any help is appreciated, thanks!
0
Comment
Question by:Uptime Legal Systems
3 Comments
 
LVL 39

Assisted Solution

by:footech
footech earned 100 total points
ID: 40591738
Hard to say without knowing what the variables contain.
Try comparing the IP with this regex (I'll just use $ip to represent the IP) in a Where-Object scriptblock.
$ip -notmatch "192\.168\.125\.((25[0-5])|(2[0-4][0-9])|(1[0-9][0-9])|(0?[0-9]?[0-9])|0?0?([0-9]))$"

Open in new window

0
 
LVL 69

Accepted Solution

by:
Qlemo earned 400 total points
ID: 40591870
Since we know the value is an IP, a more simple approach can be used:
# get ip addresses that are not already in firewall rule.
$w = $g | where {$_.Name.Length -gt 1
 -and  !($arRemote -contains $_.Name + '/255.255.255.255')
 -and $_.Name -notlike '192.168.125.*'} 

# add IPs to firewall rule
$w| %{$ar.remoteaddresses += ',' + $_.Name} 

Open in new window

0
 
LVL 6

Author Closing Comment

by:Uptime Legal Systems
ID: 40591892
Ah!  I see what I was doing wrong, thanks for the help I'll be able to use this.
0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Utilizing an array to gracefully append to a list of EmailAddresses
A brief introduction to what I consider to be the best editor for PowerShell.
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question