Solved

Powershell Script Modification

Posted on 2015-02-05
3
145 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 68

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 Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

When you start your Windows 10 PC and got an "Operating system not found" error or just saw  "Auto repair for startup" or a blinking cursor with black screen. A loop for Auto repair will start but fix nothing.  You will be panic as there are no back…
Possible fixes for Windows 7 and Windows Server 2008 updating problem. Solutions mentioned are from Microsoft themselves. I started a case with them from our Microsoft Silver Partner option to open a case and get direct support from Microsoft. If s…
This Micro Tutorial will give you a basic overview of Windows DVD Burner through its features and interface. This will be demonstrated using Windows 7 operating system.
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now