Python Forum

Full Version: PyAD search function adquery
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi everyone,

I'm trying to search inside Active Directory with PyAD but it's not clear...

I've tried this (from : https://zakird.github.io/pyad/pyad.html#...-directory)

from pyad import adquery

q = adquery.ADQuery()

q.execute_query(
	attributes = ["distinguishedName", "description"],
	where_clause = "objectClass = 'user'",
	base_dn = "CN=users, DC=Test, DC=internal"
)

for row in q.get_results():
	print(row["distinguishedName"])
This give me a list.

But I would like to add more criteria the reduce the result.

I tried few thing including this last one ->
q.execute_query(
	attributes = ["distinguishedName", "description"],
	where_clause = ["objectClass = 'user'","CN = 'John*'"],
	base_dn = "CN=users, DC=Test, DC=internal"
)
But that give me also an error (TypeError: sequence item 2: expected str instance, list found)
So I cannot feed where_clause a list :/

Any ideas ?
try
where_clause = "objectClass = 'user' and CN = 'John*'"
@buran it worked ! thanks !