Ambiguous Name Resolution in pyad

117 Views Asked by At

Is there a way to search for a user with say "bob" anywhere in their first name or last name or even full name in pyad?

I know in c# we can write:

string nameSearch = "bob";
Filter = "(&(objectClass=User)(anr=" + nameSearch + "))"

but how would we do this for pyad? I have:

import pyad.adquery, pyad.aduser

username = "bob"

q = pyad.adquery.ADQuery()

q.execute_query(
    attributes = ["givenName", "sn", "mail", "title", "l", "c", "manager"],
    where_clause = "givenName = '{}'".format(username),
    base_dn = "DC=company,DC=com"
)

for row in q.get_results():
    print (row["givenName"] + " " + row["sn"])

But this only finds anyone with the name Bob as their given name.

1

There are 1 best solutions below

0
On

Figured it out (rather sheepishly):

import pyad.adquery, pyad.aduser

username = "bob"

q = pyad.adquery.ADQuery()

q.execute_query(
    attributes = ["anr", "givenName", "sn", "mail", "title", "l", "c", "manager"],
    where_clause = "anr = '{}'".format(username),
    base_dn = "DC=company,DC=com"
)

for row in q.get_results():
    print (row["givenName"] + " " + row["sn"])