Warm tip: This article is reproduced from stackoverflow.com, please click
active-directory ldap ms-access vba

Get organizationUnit from LDAP with VBA

发布于 2020-04-04 10:10:05

I'm working with Access 2003 and already have a code that extracts a lot of data from LDAP. Here is what I got:

Set rootDSE = GetObject("LDAP://RootDSE")
domainContainer = rootDSE.Get("defaultNamingContext")

conn.provider = "ADSDSOObject"
conn.Open "ADs Provider"

ldapStr = "<LDAP://" & domainContainer & ">;(& (mailnickname=" & nickname & ") (| (&(objectCategory=person)(objectClass=user)(!(homeMDB=*))(!(msExchHomeServerName=*)))(&(objectCategory=person)(objectClass=user)(|(homeMDB=*)(msExchHomeServerName=*))) ));adspath;subtree"
exchangeRS.Open ldapStr, conn, adOpenStatic, adLockReadOnly
exchangeRS.MoveFirst

Do Until exchangeRS.EOF
    Set oUser = GetObject(exchangeRS.fields(0).value)

    ' The properties below are working
    'oUser.firstName
    'oUser.displayName
    'oUser.title
    'oUser.telephoneNumber
    'oUser.mobile
    'oUser.faxNumber
    'oUser.streetAddress
    'oUser.l
    'oUser.postalCode
    'oUser.mail
Next

I'm able to get a lot of informations for each person in the LDAP database. However, I would also like to get the structural unit. However, oUser.organizationUnit doesn't exit and oUser.OU only contains the top unit, which isn't what I want.

Is there any way to list all properties of oUser to find the right one? Is the ldapStr missing something?

Here is an image of what I want to get (sorry it it's in French):

Unit

Is it possible that this is not stored in LDAP? If not, any way to get it from Outlook address book? But I would really prefer getting it from LDAP actually, as every other single information is actually there (which tends me to believe this should be there too).

Questioner
dan
Viewed
47
dan 2012-10-22 08:57

The result of all my testing showed me that this data isn't stored in LDAP.