Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Powershell Script Modification

Posted on 2015-02-05
3
150 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 40

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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this article, I will show you HOW TO: Install VMware Tools for Windows on a VMware Windows virtual machine on a VMware vSphere Hypervisor 6.5 (ESXi 6.5) Host Server, using the VMware Host Client. The virtual machine has Windows Server 2016 instal…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

829 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