We help IT Professionals succeed at work.

match , notmatch operators and filtering

davesnb asked
Last Modified: 2012-05-31
I have a line of code below using the Quest.ActiveRoles.ADManagement snapin that will successfully find the users who are Domain Admins in the "testglobal" group . However, if I replace the -match with -notmatch it will display all users including the Domain Admins. I always thought conditional not operators are a true negative form. Is this not the case? Wondering if this is a bug or  because memberof is of type noteproperty perhaps I have to expand the list for the -notmatch?

Get-QADUser -memberof clientairglobal |where {($_.memberof -match "DomainAdmins")} | select name,memberof

Example output of -match

Name     : Joe Smith
MemberOf : {CN=clientairGlobal,OU=clientair,OU=ClientAccts,DC=Corporatedom,DC=ca, CN=CorporatedomGlobal,OU=Corporatedom,OU=ClientAccts,DC=Corporatedom,
           DC=ca, CN=Domain Admins,CN=Users,DC=Corporatedom,DC=ca}

Example output of -notmatch :

Name     : testBPS
MemberOf : {CN=clientairGlobal,OU=clientair,OU=ClientAccts,DC=Corpratedom,DC=ca}

Name     : cayekap2
MemberOf : {CN=clientairGlobal,OU=clientair,OU=ClientAccts,DC=Corpratedom,DC=ca}

Name     : cacsamgmt
MemberOf : {CN=clientairGlobal,OU=clientair,OU=ClientAccts,DC=Corpratedom,DC=ca}

Name     : caywgbag
MemberOf : {CN=clientairGlobal,OU=clientair,OU=ClientAccts,DC=Corpratedom,DC=ca}

Name     : caythacc8
MemberOf : {CN=clientairGlobal,OU=clientair,OU=ClientAccts,DC=Corpratedom,DC=ca}

Name     : Joe Smith
MemberOf : {CN=clientairGlobal,OU=clientair,OU=ClientAccts,DC=Corpratedom,DC=ca, CN=CorpratedomGlobal,OU=Corpratedom,OU=ClientAccts,DC=Corpratedom,
           DC=ca, CN=Domain Admins,CN=Users,DC=Corpratedom,DC=ca}
Watch Question

Gary DewrellSenior Network Administrator

Davesnb it works for me. I did have to ad a space in "Domain Admins"


There is a space ,sorry, the post should read :

Get-QADUser -memberof clientairglobal |where {($_.memberof -match "Domain Admins")} | select name,memberof

output results are same, problem still exists
Senior Network Administrator
This one is on us!
(Get your first solution completely free - no credit card required)


So that worked using the parameter, but wondering if this is a bug or I am misinterpreting the context of -notmatch.
Gary DewrellSenior Network Administrator

Can't say for sure but my theory is that it is evaluating it on a group by group. So -nomatch is true for some of them.  Total guess though. Fortunatley Quest does a great job on thier tools.

I did add it to my list of questions to ask Microsoft at TechEd this year. :)
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.