Jump to content

Query LDAP


Recommended Posts

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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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

Link to comment
Share on other sites

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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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
Link to comment
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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...