Solved

Script is not working

Posted on 2016-11-11
3
44 Views
Last Modified: 2016-11-11
There are multiple groups with naming convention as XXXX_GPOAXXXX and XXXX_OUAXXXX and I am trying to search all of them using below script.

Can anyone tell me what is wrong and why it is not working?

Get-ADGroup -filter * | Where-Object {($_.name -match "_gpoadm*") -and ($_.name -match "_OUad*")} | select name

Thanks!!
0
Comment
Question by:A D
[X]
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
3 Comments
 
LVL 85

Assisted Solution

by:oBdA
oBdA earned 250 total points
ID: 41883735
You're looking for names that match both substrings. Use "-or" instead of "-and":
Get-ADGroup -filter * | Where-Object {($_.name -match "_gpoadm*") -or ($_.name -match "_OUad*")} | select name

Open in new window

1
 
LVL 7

Accepted Solution

by:
David Sankovsky earned 250 total points
ID: 41883747
Just like oBdA saidyou need the or operand

It's a rather common mistakes for people with no programming or advanced mathematics training.

Assume you have a condition called A and another called B.

if your looking for situations that satisfy A and B - in programming that means that you will receive true ONLY if both A AND B are true.

OR will result in true if either A OR B OR BOTH are true.

or if put in a table (T is TRUE F is FALSE)

(OR)     A   B      Result
            T    T       T
            T    F       T
            F    T       T
            F    F       F

(AND)     A   B      Result
               T    T       T
               T    F       F
               F    T       F
               F    F       F
0
 

Author Closing Comment

by:A D
ID: 41883761
Thanks David and oBdA. It will help me a lot and yes i am just starting with Powershell so you guys can expect a lot more coming from me.

Thanks again guys!!. Really appreciate the help.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Always backup Domain, SYSVOL etc.using processes according to Microsoft Best Practices. This is meant as a disaster recovery process for small environments that did not implement backup processes and did not run a secondary domain controller that ne…
Here's a look at newsworthy articles and community happenings during the last month.
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
Suggested Courses

630 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