Sign in to follow this  
Followers 0
richie6700

Query LDAP

22 posts in this topic

Hy!!

Sorry for my bad English....

Can you help me??

How execute this query with Autoit : ldap:///ou=people,o=domain.fr??sub?(&(objectclass=person)(!(employeenumber=stage)))???

Thx

Richie

Share this post


Link to post
Share on other sites



Hi Richie,

welcome to AutoIt and the forum!

There is an Active Directory UDF (User Defined Functions) available that has function _AD_GetObjectsInOU that does exaclty what you need:

#include 
_AD_Open()
$aResult = _AD_GetObjectsInOU("OU where to start searching", "(&(objectclass=person)(!(employeenumber=stage)))", 2, "enter the properties you want returned")
_AD_Close()

For download please see my signature.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Thx for your answer.

I don't want use the Active Directory but only the LDAP... You see what i want?? Or not?

I want to list all user of a dynamic group. When I see with LDAP Browser there are in this group:

MemberURL = ldap:///ou=people,o=domain.fr??sub?(&(objectclass=person)(!(employeenumber=stage))). I think this URL list all the user of this dynamic groups.

In fact, when I write this on IE : LDAP://ldap.domain.fr:389/ou=people,o=domain.fr(&(objectclass=person)(!(employeenumber=stage))) it appears all the user of dynamic groups...

How can execute this URL LDAP with autoit??

Richie

Edited by richie6700

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

LDAP stands for "Lightweight Directory Access Protocol" and allows to access Active Directory and other Directory Services like Novells eDirectory, Oracle Internet Directory ...

LDAP is just the vehicle to access a directory service.

Which directory do you want to access using LDAP?

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

In my LDAP I have this (with LDAP Admin)

o=domain.fr[ldap.domain.fr]

ou=access

ou=groups-dynamics : all dynamics groups

ou=People : all user with uid

When I check Active Directory (with AD Explorer) I don't have o=domain.fr, ou=groups-dynamics so it's impossible to access in ou=people,o=domain.fr because this directory is only present on LDAP....

I am new in my company... I think my company have 2 servers. One for LDAP and the other for Active Directory

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

I assume ldap.domain.fr is an Active Directory Domain Controller.

In this case you could try the following using my AD UDF:

#include 
_AD_Open("", "", "", "ldap.domain.fr")
If  @error <> 0 Then Exit MsgBox(16, "LDAP", "Open: An error has occurred.  @error: " & @error & ", @extended: " & @extended)
$aResult = _AD_GetObjectsInOU("ou=people,o=domain.fr", "(&(objectclass=person)(!(employeenumber=stage)))", 2, "samaccountname")
If  @error <> 0 Then Exit MsgBox(16, "LDAP", "Query: An error has  occurred.  @error: " & @error & ", @extended: " & @extended)
_ArrayDisplay($aResult)
_AD_Close()

I'm not 100% sure so you might get an error but this can be sorted out.

BTW: I forgot - for download of the AD UDF please see my signature

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

No, ldap.domain.fr is not a domain controller...

I have this error : Query : An error has occurred. @error : 1, @extended:0

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Not bad for the first try :huh2:

The connect to ldap.domain.fr was successful.

@error = 1 means: OU does not exist. In this case the notation of "ou=people,o=domain.fr" is invalid (I expected that).

Could you please try the following adopted script:

#include 
_AD_Open("", "", "", "ldap.domain.fr")
If  @error <> 0 Then Exit MsgBox(16, "LDAP", "Open: An error has occurred.  @error: " & @error & ", @extended: " & @extended)
$aResult = _AD_GetObjectsInOU("", "(&(objectclass=person)(!(employeenumber=stage)))", 2, "employeenumber","")
If  @error <> 0 Then Exit MsgBox(16, "LDAP", "Query: An error has  occurred.  @error: " & @error & ", @extended: " & @extended)
_ArrayDisplay($aResult)
_AD_Close()
Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

LOL :huh2: I have :

Query : an occured..... @error:2, @extended:0...

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

My fault - a typo in the _AD_GetObjectsInOu function call. Could you please copy the code from post and run it again?

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Same error.... (I don't find samaccountname,distinguishedname when I search with LDAP Admin in ou=people)

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Could you please post a screenshot how an item in ou=people looks like? I would prefer a screen where fieldnames and content is displayed.

BTW: What LDAP Browser do you use when you connect to ldap.domain.fr?

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

I once again changed the script in post #8 to only return the employeenumber. Hope it works now :huh2:


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

I've been searching the internet and I think you try to connect to a Novell eDirectory / NDS Server. This is based on the form of the starting OU "ou=people,o=domain.fr".

I hope my last version of the test script returns any results. If not I know at least where to search ...


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

I have the same error.... ;)

Yes maybe I use Novell eDirectory / NDS Server... I don't know. :huh2:

Look how to connect on LDAP Server :

I have this with my script

Const $LDAPBaseDN = "ou=people,o=domain.fr"
Const $LDAPPort = "389"
Const $LDAPServer = "ldap.domain.fr"
Const $LDAPAddress = $LDAPServer & ":" & $LDAPPort & "/" & $LDAPBaseDN

$ObjLDAP = ObjGet ("LDAP://" & $LDAPAddress)
If @error Then
    MsgBox (4096, "LDAP Connection", $LDAPServer & " connection error")
    Exit
EndIf

For $ObjMembers In $ObjLDAP
MsgBox(0,"",$ObjMembers.uid)
next

It's OK... But how I can Execute this filter (&(objectclass=person)(!(employeenumber=stage)))?

Edited by richie6700

Share this post


Link to post
Share on other sites

I found the following example on the internet:

option explicit

Sub Get_LDAP_Data()
    Dim con,rs,Com,strValue
    dim i,strMember,strGroup
    Set con = CreateObject("ADODB.Connection")
    con.provider ="ADsDSOObject"
    con.Properties("User ID") = "cn=UserID,o=AAA" ' specify your UserID and containter with AAA being the container
    con.Properties("Password") = "Password" ' specify your password
    con.open "Active Directory Provider"
    Set Com = CreateObject("ADODB.Command")
    Set Com.ActiveConnection = con 

    'You have to specify your LDAP server and the container in the following line
    Com.CommandText ="select cn,member from 'LDAP://YourLdapServer.com/o=AAA' where objectClass = 'groupOfNames'"
    Set rs = Com.Execute 

    strValue = "nds_group|&|member_id"

    do until rs.eof
        strGroup = rs("cn")
        strMember = rs("member")
                                
        If isarray(strMember) then
            for i=0 to ubound(strMember)
                strValue = strValue & vbcrlf & strGroup(0) & "|&|" & Friendly_Context(strMember(i))
            next
        end if
        
        rs.MoveNext
    loop
    wscript.echo strValue
    rs.Close

    con.Close
    Set rs = Nothing
    Set con = Nothing
End Sub

Function Friendly_Context(aryValue)
    dim i,strValue,aryValue2
    aryValue = split(aryValue,",")
    
    For i=0 to ubound(aryValue)
        aryValue2 = split(aryValue(i),"=")      
        if strValue = "" then
            strValue = aryValue2(1)
        else
            strValue = strValue & "." & aryValue2(1)
        end if      
    Next
    
    Friendly_Context = strValue
End Function

call Get_LDAP_Data()
Get_LDAP_Data should do what you need.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

This is not autoit script?

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

It's Visual Basic but it should be easy to translate to AutoIt.

I'm on vacation till 27.6. and unfortunately don't have the time to translate it right now.

If you can wait I'll give it a try after my vacation.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

No prob...

Thank you very much

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  
Followers 0