Solved

Script is not working

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
Recently, Microsoft released a best-practice guide for securing Active Directory. It's a whopping 300+ pages long. Those of us tasked with securing our company’s databases and systems would, ideally, have time to devote to learning the ins and outs…
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…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

752 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