Jump to content
Sign in to follow this  
Anders Westerberg

generic ldap function but a bit slow

Recommended Posts

Anders Westerberg

Hi. I'v been using AutoIt for a couple of years now but this is my first post here so please inform me of any errors I make.

I have written a small ldap function that I use in a couple of scripts but it is very slow when querying large number of objects/attributes. An example, doing a query that results in 500 objects and 15 attributes on each object will take over a minute. The actual ldap query in this case only takes about 3 seconds.

I do not claim to be a programmer in any way so if anyone could help me speed this up I would be very grateful!

Oh, and about the function. It works.. almost.. I have some issues with microsofts implementation of ldapsearch. I can not get values from some attributes, "cn" does not work, "groupmembership" does not work.. don't know why but don't really need them anyway.

If I want to check if a user is a member of a specific group I just do a search like this (when searching a novell ldap tree, would be different group attribute in openldap):


)","fullname",ldapserver,basecontext) if it returns "" then the user is not a member of that group. Otherwise it will return an array.

usage, ldapsearch(ldapfiler,attributestoreturn,ldapserver,basecontext) if the query matches any objects it will return an array with the number of objects that matched in array[0] and then the DN of the first match and the attributes.. then the second DN that matches and the attributes.. and so on..

As I'm editing this i realize just how bad I am at explaining how this works.. :whistle:

edit.. cant get the code below to show tabs.. seems a bit garbled..


func ldapsearch($ldapfilter,$attributes,$ldapserver,$basecontext)

Local $objConnection,$objRecordSet,$i,$j,$temp,$dn

Local $attrarray,$tempstring,$attributecount


$objConnection = ObjCreate("ADODB.Connection")

$objConnection.Provider = "ADSDSOObject"

$objConnection.open = "ADs Provider"

$objRecordSet = $objConnection.Execute("<LDAP://" & $ldapserver & "/" & $basecontext & ">;" & $ldapfilter & ";ADsPath," & $attributes & ";subtree")

if $objRecordSet.EOF then return ""


while not ($objRecordSet.EOF)




for $i=1 to $attributecount[0]



if IsArray($temp)=1 then ;if the attribute is a multistringattribute then microsofts ldapsearch will return an array

if UBound($temp)>1 Then

for $j=0 to (UBound($temp)-1)

$tempstring&=$temp[$j] & ", "













$attrarray[0]=(UBound($attrarray)-1) / ($attributecount[0]+1)

return $attrarray


Edited by Anders Westerberg

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this