Re: On ADSI and LDAP
- From: "Ed Crowley [MVP]" <curspice@xxxxxxxxxxxxxx>
- Date: Sun, 12 Aug 2007 11:45:25 -0700
Wouldn't it be easier to do an LDAP search for the samAccountName and return
the distinguishedName attribute?
--
Ed Crowley
MVP - Exchange
"Protecting the world from PSTs and brick backups!"
"Richard Mueller [MVP]" <rlmueller-nospam@xxxxxxxxxxxxxxxxxxxx> wrote in
message news:uC8s2nE3HHA.1204@xxxxxxxxxxxxxxxxxxxxxxx
jimt wrote:
How can I extract a user DN given its sam account name?
I need to put into a variable the user DN in the format
"CN=something,OU=...(nested OUs),DC=....,DC=...,DC=..."
I have nested OUs so I have to use some kind of recursion i guess.
Use the NameTranslate object for this. For example:
============
' Constants for the NameTranslate object.
Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1
' Specify the NetBIOS name of the domain and the NT name of the user
' (The same as the value of the sAMAccountName attribute).
strNTName = "MyDomain\TestUser"
' Use the NameTranslate object to convert the NT user name to the
' Distinguished Name required for the LDAP provider.
Set objTrans = CreateObject("NameTranslate")
' Initialize NameTranslate by locating the Global Catalog.
objTrans.Init ADS_NAME_INITTYPE_GC, ""
' Use the Set method to specify the NT format of the object name.
objTrans.Set ADS_NAME_TYPE_NT4, strNTName
' Use the Get method to retrieve the RPC 1779 Distinguished Name.
strUserDN = objTrans.Get(ADS_NAME_TYPE_1779)
' Bind to the user object in Active Directory with the LDAP provider.
Set objUser = GetObject("LDAP://" & strUserDN)
============
For more see this link:
http://www.rlmueller.net/NameTranslateFAQ.htm
--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--
.
- Follow-Ups:
- Re: On ADSI and LDAP
- From: Richard Mueller [MVP]
- Re: On ADSI and LDAP
- From: jimt
- Re: On ADSI and LDAP
- References:
- Re: On ADSI and LDAP
- From: Richard Mueller [MVP]
- Re: On ADSI and LDAP
- Prev by Date: Re: Script to speicfy which drive a USB storage device must use
- Next by Date: Re: Reference for the LDAP object
- Previous by thread: Re: On ADSI and LDAP
- Next by thread: Re: On ADSI and LDAP
- Index(es):