Solved

Script is not working

Posted on 2016-11-11
3
28 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 83

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 6

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

Join & Write a Comment

Microsoft Windows Server Update Service (WSUS) is free for everyone, but it lacks of some desirable features like send an e-mail to the administrator with the status of all computers on the WSUS server. This article is based on my PowerShell script …
"Migrate" an SMTP relay receive connector to a new server using info from an old server.
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 tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

760 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

18 Experts available now in Live!

Get 1:1 Help Now