# LDAP Active Directory Query

**URL:** <https://forum.inductiveautomation.com/t/ldap-active-directory-query/15192>\
**Category:** Ignition\
**Created:** [August 29, 2017, 1:44pm UTC](https://forum.inductiveautomation.com/t/ldap-active-directory-query/15192 "2017-08-29T13:44:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![focusengsk](https://avatars.discourse-cdn.com/v4/letter/f/46a35a/32.png) [@focusengsk](https://forum.inductiveautomation.com/u/focusengsk)\
**Post date:** [August 29, 2017, 1:44pm UTC](https://forum.inductiveautomation.com/t/ldap-active-directory-query/15192/1 "2017-08-29T13:44:36Z")

</div>

Hello,

I am trying to query user accounts on AD using LDAP query. When I run the following script I get no result, I am hoping to get accountExpires info for any user logged in.

from java.util import \*  
from javax.naming import \*  
from javax.naming.directory import \*  
from javax.naming.ldap import \*  
import java.util.Hashtable  
import java.util.Enumeration  
env = Hashtable()  
env.put(Context.INITIAL\_CONTEXT\_FACTORY, “com.sun.jndi.ldap.LdapCtxFactory”)  
env.put(Context.PROVIDER\_URL, “ldap://serverip:389”)  
env.put(Context.SECURITY\_AUTHENTICATION, “simple”)  
env.put(Context.SECURITY\_PRINCIPAL, “username”)  
env.put(Context.SECURITY\_CREDENTIALS, “password”)  
ctx = InitialLdapContext(env,None)  
searchCtls = SearchControls()  
returnedAtts = (“sn”,“givenName”,“cn”)  
searchCtls.setReturningAttributes(returnedAtts)  
searchCtls.setSearchScope(SearchControls.SUBTREE\_SCOPE)  
pageSize = 1000  
cookie = None  
ctx.setRequestControls([PagedResultsControl(pageSize,Control.CRITICAL)])  
results = ctx.search(“dc=xxx,dc=xxx,dc=xxx”,"(&(objectCategory=person)(objectClass=user))",searchCtls)  
while (results != “” and results.hasMoreElements()):  
entry = results.next()  
attrs=entry.getAttributes()  
try:  
print attrs.get(“givenName”).get() + " " + attrs.get(“sn”).get()  
except:  
pass

Any help would be much appreciated, I get no errors, but also no print of attributes!

---

<div class="post-metadata">

**Author:** ![focusengsk](https://avatars.discourse-cdn.com/v4/letter/f/46a35a/32.png) [@focusengsk](https://forum.inductiveautomation.com/u/focusengsk)\
**Post date:** [August 30, 2017, 9:16pm UTC](https://forum.inductiveautomation.com/t/ldap-active-directory-query/15192/2 "2017-08-30T21:16:51Z")

</div>

Specifically, we want to query the users password expiration date. We are struggling to find example of this, not much help available from IT department either.
