ADSI question 
Author Message
 ADSI question

I'm creating a script that should instantiate an object representing user in
Active Directory.

I'm using ADSI and the LDAP provider as I want to access some properties
that are not accessible through the WinNT provider.
My problem is that I only have the logonname (sAMAccountType) of the user,
and not the commonname (CN) or distinguesed name (DN) which I need for LDAP.
Ex.: GetObject("LDAP://CN=John Doe, CN=Users, DC=test, DC=com")

How do I lookup the CN or DN when having the logon name only ?

I can off cause enumerate all users the the AD and check the sAMAccountType
property, but I don't like this solution.



Sun, 03 Oct 2004 01:32:19 GMT  
 ADSI question
You can use the NameTranslate method on the NT name.  The
basic code looks like this:

const ADS_NAME_INITTYPE_SERVER = 2
const ADS_NAME_TYPE_1779 = 1
const ADS_NAME_TYPE_NT4 = 3

Set WshNetwork = WScript.CreateObject("WScript.Network")
Set nto = CreateObject("NameTranslate")
nto.Init ADS_NAME_INITTYPE_SERVER, "DSCYFADC001"
nto.Set ADS_NAME_TYPE_NT4, "YourDomain\" &
WshNetwork.UserName
result = nto.Get(ADS_NAME_TYPE_1779)

The result field will have the user's full path.  You will
of course have to replace YourDomain with the domain name
the user is logging in to.  This works considerably faster
than querying ADO and works fine in Win9x.

Quote:
>-----Original Message-----
>I'm creating a script that should instantiate an object

representing user in
Quote:
>Active Directory.

>I'm using ADSI and the LDAP provider as I want to access
some properties
>that are not accessible through the WinNT provider.
>My problem is that I only have the logonname

(sAMAccountType) of the user,
Quote:
>and not the commonname (CN) or distinguesed name (DN)

which I need for LDAP.
Quote:
>Ex.: GetObject("LDAP://CN=John Doe, CN=Users, DC=test,
DC=com")

>How do I lookup the CN or DN when having the logon name
only ?

>I can off cause enumerate all users the the AD and check
the sAMAccountType
>property, but I don't like this solution.

>.



Sun, 03 Oct 2004 02:12:04 GMT  
 ADSI question
Working perfect - Thanks !


Sun, 03 Oct 2004 05:40:36 GMT  
 ADSI question
Here is another way using ADO

sQuery="select adspath " &_
        "from 'LDAP://DC=Domain,DC=Com" &_
        "where sAMAccountName='johnd'"

Set oConn  = CreateObject("ADODB.Connection")
oConn.Provider = "ADSDSOObject"
oConn.Open "ADs Provider"

Set oRS = oConn.Execute(sQuery)
Set oUser = GetObject(oRS("adsPath"))

MsgBox oUser.FullName

or if you are using in a logon script try this method

'Bind Active Directory for current logon session
set adsys = CreateObject("ADSystemInfo")
'Bind to User Using LDAP
set oUser=getobject("LDAP://" & adsys.UserName)
'Bind to Computer Using LDAP
set oComputer=getobject("LDAP://" & adsys.ComputerName)


Quote:
> You can use the NameTranslate method on the NT name.  The
> basic code looks like this:

> const ADS_NAME_INITTYPE_SERVER = 2
> const ADS_NAME_TYPE_1779 = 1
> const ADS_NAME_TYPE_NT4 = 3

> Set WshNetwork = WScript.CreateObject("WScript.Network")
> Set nto = CreateObject("NameTranslate")
> nto.Init ADS_NAME_INITTYPE_SERVER, "DSCYFADC001"
> nto.Set ADS_NAME_TYPE_NT4, "YourDomain\" &
> WshNetwork.UserName
> result = nto.Get(ADS_NAME_TYPE_1779)

> The result field will have the user's full path.  You will
> of course have to replace YourDomain with the domain name
> the user is logging in to.  This works considerably faster
> than querying ADO and works fine in Win9x.

> >-----Original Message-----
> >I'm creating a script that should instantiate an object
> representing user in
> >Active Directory.

> >I'm using ADSI and the LDAP provider as I want to access
> some properties
> >that are not accessible through the WinNT provider.
> >My problem is that I only have the logonname
> (sAMAccountType) of the user,
> >and not the commonname (CN) or distinguesed name (DN)
> which I need for LDAP.
> >Ex.: GetObject("LDAP://CN=John Doe, CN=Users, DC=test,
> DC=com")

> >How do I lookup the CN or DN when having the logon name
> only ?

> >I can off cause enumerate all users the the AD and check
> the sAMAccountType
> >property, but I don't like this solution.

> >.



Sun, 03 Oct 2004 06:46:40 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Stupid VBScript/ADSI question

2. ADSI Question

3. Another ADSI question...

4. Stupid VBScript/ADSI question

5. ADSI Question

6. ADSI questions user properties

7. ADSI Question

8. ADSI Question

9. ADSI question

10. ADSI question (can I just installl it on our PDC?)

11. ADSI question (can I just installl it on our PDC?)

12. VBS and ADSI Object begginer question.

 

 
Powered by phpBB® Forum Software