I need help for some LDAP scripting.
I need to know a specific LDAP path for a user... but how.

input:
Username

output:
cn=USERNAME,ou=HQ,ou=HADERSLEV,dc=DOMAIN,dc=NET"

Is that possible...


Best regards

Henrik holm

Re: return users LDAP path by E

E
Thu Jan 25 08:49:32 CST 2007

Here is what used, supply the Winnt login name, and it returns the FQ object name. I used the NT
name to keep from getting multiple returns.

Beware line wrap
<--------Function-----------<
Function FindUser(strNetworkID)

Const ADS_SCOPE_BASE = 0
Const ADS_SCOPE_ONELEVEL = 1
Const ADS_SCOPE_SUBTREE = 2

Dim objCon, objCmd, objRDSE, objRS

Set objCon = CreateObject("ADODB.Connection")
Set objCmd = CreateObject("ADODB.Command")
Set objRDSE = GetObject("LDAP://RootDSE")

With objCon

.Provider = "ADsDSOObject"
.Open

End With

Set objCmd.ActiveConnection = objCon

With objCmd
.Properties("Page Size") = 1000
.Properties("Timeout") = 90
.Properties("SearchScope") = ADS_SCOPE_SUBTREE

.CommandText = "<LDAP://" & objRDSE.Get("defaultNamingContext") & ">;(objectClass=User);name,ADsPath"

Set objRS = .Execute
End With

objRS.Find "name='" & strNetworkID & "'"
If objRS.EOF Then FindUser = "" Else FindUser = objRS("ADsPath")

objRS.Close
objCon.Close

Set objRS = Nothing
Set objCmd = Nothing
Set objCon = Nothing
Set objRDSE = Nothing

End Function

<--------End Function-------<

Henrik Holm wrote:
> I need help for some LDAP scripting.
> I need to know a specific LDAP path for a user... but how.
>
> input:
> Username
>
> output:
> cn=USERNAME,ou=HQ,ou=HADERSLEV,dc=DOMAIN,dc=NET"
>
> Is that possible...
>
>
> Best regards
>
> Henrik holm

Re: return users LDAP path by HenrikHolm

HenrikHolm
Thu Jan 25 09:21:01 CST 2007

Almost, I realize what I only have the samaccountname as input, the output is
just perfekt.?

Where can I find a list of items on the user account?

Regards henrik

"E C H (He of too much code)" wrote:

> Here is what used, supply the Winnt login name, and it returns the FQ object name. I used the NT
> name to keep from getting multiple returns.
>
> Beware line wrap
> <--------Function-----------<
> Function FindUser(strNetworkID)
>
> Const ADS_SCOPE_BASE = 0
> Const ADS_SCOPE_ONELEVEL = 1
> Const ADS_SCOPE_SUBTREE = 2
>
> Dim objCon, objCmd, objRDSE, objRS
>
> Set objCon = CreateObject("ADODB.Connection")
> Set objCmd = CreateObject("ADODB.Command")
> Set objRDSE = GetObject("LDAP://RootDSE")
>
> With objCon
>
> .Provider = "ADsDSOObject"
> .Open
>
> End With
>
> Set objCmd.ActiveConnection = objCon
>
> With objCmd
> .Properties("Page Size") = 1000
> .Properties("Timeout") = 90
> .Properties("SearchScope") = ADS_SCOPE_SUBTREE
>
> .CommandText = "<LDAP://" & objRDSE.Get("defaultNamingContext") & ">;(objectClass=User);name,ADsPath"
>
> Set objRS = .Execute
> End With
>
> objRS.Find "name='" & strNetworkID & "'"
> If objRS.EOF Then FindUser = "" Else FindUser = objRS("ADsPath")
>
> objRS.Close
> objCon.Close
>
> Set objRS = Nothing
> Set objCmd = Nothing
> Set objCon = Nothing
> Set objRDSE = Nothing
>
> End Function
>
> <--------End Function-------<
>
> Henrik Holm wrote:
> > I need help for some LDAP scripting.
> > I need to know a specific LDAP path for a user... but how.
> >
> > input:
> > Username
> >
> > output:
> > cn=USERNAME,ou=HQ,ou=HADERSLEV,dc=DOMAIN,dc=NET"
> >
> > Is that possible...
> >
> >
> > Best regards
> >
> > Henrik holm
>

Re: return users LDAP path by Richard

Richard
Fri Jan 26 12:21:33 CST 2007

The most straightforward method to convert the NT name (pre-Windows 2000
logon name) of a user to the Distinguished Name is to use the NameTranslate
object. This seems more efficient than searching all of AD. See this link
for details:

http://www.rlmueller.net/NameTranslateFAQ.htm

See #6 for a quick example. See #16 if you don't want to hard code the
NetBIOS name of the domain (you can retrieve the DNS name from the RootDSE
object and use NameTranslate to convert this to the NetBIOS name of the
domain).

If by a list of items on the user account, you mean the attributes
available, see this link:

http://www.rlmueller.net/UserAttributes.htm

The first spreadsheet documents that attributes of user objects that
corresponds to fields in ADUC. The second spreadsheet documents all
attributes in Active Directory, showing which apply to user objects.

--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab web site - http://www.rlmueller.net
--

"Henrik Holm" <HenrikHolm@discussions.microsoft.com> wrote in message
news:37E65B64-AC1F-40DC-8FDD-3730BB8BE332@microsoft.com...
> Almost, I realize what I only have the samaccountname as input, the output
is
> just perfekt.?
>
> Where can I find a list of items on the user account?
>
> Regards henrik
>
> "E C H (He of too much code)" wrote:
>
> > Here is what used, supply the Winnt login name, and it returns the FQ
object name. I used the NT
> > name to keep from getting multiple returns.
> >
> > Beware line wrap
> > <--------Function-----------<
> > Function FindUser(strNetworkID)
> >
> > Const ADS_SCOPE_BASE = 0
> > Const ADS_SCOPE_ONELEVEL = 1
> > Const ADS_SCOPE_SUBTREE = 2
> >
> > Dim objCon, objCmd, objRDSE, objRS
> >
> > Set objCon = CreateObject("ADODB.Connection")
> > Set objCmd = CreateObject("ADODB.Command")
> > Set objRDSE = GetObject("LDAP://RootDSE")
> >
> > With objCon
> >
> > .Provider = "ADsDSOObject"
> > .Open
> >
> > End With
> >
> > Set objCmd.ActiveConnection = objCon
> >
> > With objCmd
> > .Properties("Page Size") = 1000
> > .Properties("Timeout") = 90
> > .Properties("SearchScope") = ADS_SCOPE_SUBTREE
> >
> > .CommandText = "<LDAP://" & objRDSE.Get("defaultNamingContext") &
">;(objectClass=User);name,ADsPath"
> >
> > Set objRS = .Execute
> > End With
> >
> > objRS.Find "name='" & strNetworkID & "'"
> > If objRS.EOF Then FindUser = "" Else FindUser = objRS("ADsPath")
> >
> > objRS.Close
> > objCon.Close
> >
> > Set objRS = Nothing
> > Set objCmd = Nothing
> > Set objCon = Nothing
> > Set objRDSE = Nothing
> >
> > End Function
> >
> > <--------End Function-------<
> >
> > Henrik Holm wrote:
> > > I need help for some LDAP scripting.
> > > I need to know a specific LDAP path for a user... but how.
> > >
> > > input:
> > > Username
> > >
> > > output:
> > > cn=USERNAME,ou=HQ,ou=HADERSLEV,dc=DOMAIN,dc=NET"
> > >
> > > Is that possible...
> > >
> > >
> > > Best regards
> > >
> > > Henrik holm
> >