Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Script is not working

Posted on 2016-11-11
3
Medium Priority
?
48 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:P S
3 Comments
 
LVL 85

Assisted Solution

by:oBdA
oBdA earned 1000 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 1000 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:P S
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Microsoft Office 365 is a subscriptions based service which includes services like Exchange Online and Skype for business Online. These services integrate with Microsoft's online version of Active Directory called Azure Active Directory.
In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

971 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