LDAP ADSI Active Directory - Efficiently get CN from UserName
Posted on 2003-10-30
Ok, I have been trying to figure this out all week.
I'm using Visual Basic 6 with the ADSI interface to access Active Directory. We have made our own schema extension to AD to include a 'balance' attribute to the user. We have a database with UserName, Balance and FullName in a table. What i need is an efficient way to write the balance from the database to the AD.
Heres what i've got:
Set iadsOpenDS = GetObject("LDAP:")
Set iadsUser = iadsOpenDS.OpenDSObject("LDAP://PDCName/CN=UserName,CN=Users," & g_uSetup.sLDAPDomainPath, g_uSetup.sLDAPUserName, g_uSetup.sLDAPPassword, ADS_FAST_BIND)
sBalanceInfo = FormatCurrency(rsUser("Balance"), -1, vbTrue, vbFalse) & " on " & FormatDateTime(Now(), vbShortDate) & " " & Format(Now(), "Medium Time")
iadsUser.Put "Balance", sBalanceInfo
Ok, so the problem is, I have the user's UserName (ie. the name they could use to log on to the box with) but I need their LDAP CN name so that i can bind to their object.
One way could be to search the AD from the OpenDSObject call, if this is possible? I have not seen any examples of this and tried and failed to do it with a search filter. (sAMAccountName is the same as UserName in AD)
Set iadsUser = iadsOpenDS.OpenDSObject("LDAP://PDCName/sAMAccountName=" & rsUser("UserNameBase").Value & ",CN=Users," & g_uSetup.sLDAPDomainPath, g_uSetup.sLDAPUserName, g_uSetup.sLDAPPassword, 0)
The reason I want to use the OpenDSObject is because ADS_FAST_BIND is very quick.
Or is there some kind of function I can call to quickly retrieve the user's CN? Remembering that I may have to update 10,000 users at once.