ADModify LDAP Query Help

Jorge Ocampo
Jorge Ocampo used Ask the Experts™
on
Hi,

i am trying to search all users that do not contain a proxyaddress but seemed to be getting an invalid query error, any help would be appreciated.

(objectClass=user)(!(proxyAddresses:=*@DOMAINNAME.com)))
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Kevin StanushApplication Developer

Commented:
Try:

(&(objectCategory=user)(!proxyAddresses=*))

For a visual way to do this, try Hyena (www.systemtools.com).  It will let you do this interactively by just running a query, and then you can sort on the ProxyAddresses column.

Video on modifying AD queries is here:

https://www.youtube.com/watch?v=1ONAhKyB61g

Author

Commented:
(&(objectCategory=user)(!proxyAddresses=*@DomainName.com))

also returning contacts :(
Kevin StanushApplication Developer

Commented:
Sorry, just replace objectcategory=user to objectclass=user.  If you have a huge AD environment, we can optimize it with objectcategory some, but its probably not worth it.
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
that worked :) could we also include "and" contains(@DOMAINNAME2)

summary

Must be user
Does not contain
3*filter Contains"@Domainname2.com"
PowerShell Developer
Top Expert 2010
Commented:
You can chain them all along. It only gets more complex if you make it Or instead of And.

This gives:

  • User (by class and category)
  • ProxyAddresses does not contain @domainname.com
  • ProxyAddresses does contain @domain2.com

(&(objectClass=user)(objectCategory=person)(!proxyAddresses=*@DomainName.com)(proxyAddresses=*@Domain2.com))

Open in new window

Author

Commented:
This Guy is A Wizard!
Kevin StanushApplication Developer

Commented:
Glad I could help.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial