Solved

Script is not working

Posted on 2016-11-11
3
42 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
3 Comments
 
LVL 84

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

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 …
This article runs through the process of deploying a single EXE application selectively to a group of user.
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

830 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