Python Forum

Full Version: ldap3 question, using a variable in search string
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm trying to figure out how to put in a variable in my search string for ldap3. I want to create a loop that goes through a list of usernames and does an Active Directory search thru each username.

First statement binds me to Domain Controller, the second one does a search. I'm trying to have a variable at the end of the second statement for the sAMAccountName. I want "adname" to be my variable. How do I do that?

conn = Connection([server1], user='domain\\user', password='password', auto_bind=True)

conn.search('dc=test,dc=mydomain,dc=com', '(&(objectCategory=person)(objectClass=user)(sAMAccountName=adname))')
Thanks in advance.
I got it resolved guys. Thanks!