Search code examples
c#asp.netfilteractive-directoryldap-query

How I use a "NOT" operator in the ldap filter


I use a filter for search a list of user in Active Directory...

Here is my filter example:

AD.filterung = "(&(objectClass=user)(objectCategory=user)(userAccountControl:1.2.840.113556.1.4.803:=2)(sn=)(|(telephoneNumber=)(mail=))(l=" + Werk + ")(cn=))";

It show me all user with UF_ACCOUNT_DISABLE but i want show all other User the not Unlock ...how I build a not operator in my filter. :(


Solution

  • have you tried simply with "!" ?

    AD.filterung = "(&(objectClass=user)(objectCategory=user)(!userAccountControl:1.2.840.113556.1.4.803:=2)(sn=)(|(telephoneNumber=)(mail=))(l=" + Werk + ")(cn=))";