LDAP Query for Pulling Bad UPN's

itsmevic
itsmevic used Ask the Experts™
on
Hello Experts!

    I have an LDAP query that searches through my AD environment and searches for bad UPN's.  Can you take a look at my below query and let me know if it will fly or not for doing this?

    Basically have it searching only ACTIVE user accounts and everything that IS NOT @abc.com and omitting those accounts it finds that have in their description fields NoUPN or NoUPNCheck and Omits Service Accounts OU.

**************************************************************************************************
(&(objectCategory=person)(objectClass=user)(|(!OU=*ServiceAccounts*)(!userPrincipalName=*@abc.com)(!userAccountControl:1.2.840.113556.1.4.803:=2)(!description=*NoUPN*)))

**************************************************************************************************

    Thanks for your help.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
PowerShell Developer
Top Expert 2010
Commented:
Hey again :)

This bit won't work:

OU=*ServiceAccounts*

You can't filter on OU I'm afraid, the attribute will not be populated on user accounts.

You know you have Or there?

If URP IsNot @abc.com OR IsEnabled OR Description IsNot NoUPN

Basically it's not exclusive, you probably want AND (&).

(&(objectCategory=person)(objectClass=user)(!userPrincipalName=*@abc.com)(!userAccountControl:1.2.840.113556.1.4.803:=2)(!description=*NoUPN*))

Chris

Author

Commented:
Hi there Chris so basically my best bet with this request is to use this query:

(&(objectCategory=person)(objectClass=user)(!userPrincipalName=*@abc.com)(!userAccountControl:1.2.840.113556.1.4.803:=2)(!description=*NoUPN*))
Chris DentPowerShell Developer
Top Expert 2010

Commented:

Yep, it's about as close as you'll get I think. If not yell again :)

Chris

Author

Commented:
Thanks again for your help Chris!  

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