Jump to content

ldap queury - not Active directory!


Recommended Posts

hi,

I have an issue with LDAP queury.

If using the ldap-search-tool it can search my company directory (not Active-directory related).

I need an example script for ADODB connection, not connecting to AD for searching but for global ldap queries.

I tried using this:

$serverName = "9.17.186.253"
$baseStr = "ou=bluepages,o=ibm.com"
$filterStr = "cn=zar*"

 $ado = ObjCreate("ADODB.Connection")
$ado.Provider = "ADSDSOObject"                       
$ado.Properties("User ID") = ""     
$ado.Properties("Password") = ""
$ado.Properties("Encrypt Password") = 1
$ado.Open ("ADS-Search" )

 $adoCmd = ObjCreate("ADODB.Command")            
$adoCmd.ActiveConnection = $ado                        
$adoCmd.Properties("Page Size") = 99                      
$adoCmd.Properties("Cache Results") = 1
$adoCmd.CommandText = "<LDAP://" & $serverName & "/" & $baseStr & ">;" & $filterStr & ";ADsPath;subtree" 

 $objectList = $adoCmd.Execute                        


While Not $objectList.EOF()
     $user = ObjGet($objectList.Fields("ADsPath").value)  
    If $user.displayName <> "" Then
    ConsoleWrite ($user.displayName & @CRLF)
    EndIf
    $objectList.MoveNext ()
Wend

any idea?

Link to comment
Share on other sites

I'v tried this also:

$objConnection = ObjCreate("ADODB.Connection")
$objConnection.Open ("Provider=ADsDSOObject;")
$objCommand = ObjCreate("ADODB.Command")
$objCommand.ActiveConnection = $objConnection



$objCommand.CommandText = "<LDAP://9.17.186.253:389,c=il,ou=bluepages,o=ibm.com>;(&(objectCategory=mail);subtree"
$objRecordSet = $objCommand.Execute
if $objRecordSet.RecordCount = 0 then
MsgBox(0,"","Not Found!")
else
    ConsoleWrite ($objRecordSet.Fields("mail").Value)
EndIf

but it gives me this error:

C:\My Documents\LDAP\test1.au3 (11) : ==> The requested action with this object has failed.:

$objRecordSet = $objCommand.Execute

$objRecordSet = $objCommand.Execute^ ERROR

any idea? someone?

Link to comment
Share on other sites

  • Developers

As mentioned in the PM: Are you sure you are using the correct provider for doing a LDAP call to the bluepages?

It also helps to implement a ComErrorHandler to display better error info.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

As mentioned in the PM: Are you sure you are using the correct provider for doing a LDAP call to the bluepages?

It also helps to implement a ComErrorHandler to display better error info.

Jos

Hi, Jos, Thanks for replying....

the issue is that when using WireShark (Network Sniffer) I don't even see a packet go out to the server, the application immidietly halt.

Link to comment
Share on other sites

  • Developers

just another thing, if using this application it does work:

"ldap search tool".

Is this a AutoIt3 script?

anyways as mentioned:

1. are you sure you are using the correct provider?

2. Did you add the ComErrorHandler to show better errors?

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Is this a AutoIt3 script?

anyways as mentioned:

1. are you sure you are using the correct provider?

2. Did you add the ComErrorHandler to show better errors?

I got three errors:

We intercepted a COM Error !

Number is: 80020009

Windescription is: ??5

We intercepted a COM Error !

Number is: 000000A9

Windescription is: Variable must be of type 'Object'.+>17:48:21 AutoIT3.exe ended.rc:0

I have no idea what those errors means.

Link to comment
Share on other sites

what other providers are there ? I couldn't find any on the web.

On the web...? :)

You said you were trying to search your company's LDAP directory. What makes you think your company has its LDAP directory out on the web? That would normally be hosted on an internal server controlled by the company. Have you discussed this with your company's IT people?

I would bet your error is on the $objRecordSet variable, which is not an object because the query failed. The query failed because you don't know where the LDAP server is, just as Jos said.

:o

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

hi,

the server is my company server you are right about that, but it is LDAP based and I can query it using LDAP search tools (free tools on the web).

now, regarding the issue, I got this code to make it work, it is VBS and I have no idea how to translate it to Auto-IT.

can someone please help me do it ?

' Find first names of all the zar....

Set pLDAP = CreateObject("LDAPClient.3")
Call pLDAP.Connect("9.17.186.253")

Set pAttributeNames = CreateObject("LDAPClient.StringCollection")
Call pAttributeNames.Add("givenName")
Call pAttributeNames.Add("mail")

' Find all the zar... family names...
Set pEntries = pLDAP.Search("c=il,ou=bluepages,o=ibm.com", "sn=zar*", , pAttributeNames)
For Each pEntry In pEntries
    MsgBox pEntry.Attributes("givenName").Values(0).Value
    MsgBox pEntry.Attributes("mail").Values(0).Value
Next
Edited by erezlevi
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...