Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Finding Users RDN

Posted on 2004-08-11
2
Medium Priority
?
355 Views
Last Modified: 2010-05-18
How do I search AD to find out a users RDN?  I want to create a vbscript that goes out and finds a users RDN.  Problem is that the user may be in a OU or a CN (will be used to query different users)

I know I need to bind to AD, then query the user.  Do I have to go through the GC? or can i just do an LDAP call?
0
Comment
Question by:randyt200
2 Comments
 
LVL 14

Expert Comment

by:dlwyatt82
ID: 11778284
You can search the directory for a partcular user, and then read the user's IADs::Name property to get the RDN (I believe there is also an IADs::Get_Name method to retrieve this data). See the following section of the Active Directory Programmer's Guide at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ad/ad/searching_active_directory.asp for information on how to perform a search of the directory with a query.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/adsi/adsi/iadsuser.asp details the properties and methods of IADsUser, including those it inherits from IADs (such as Name and Get_Name).
0
 
LVL 15

Accepted Solution

by:
Colosseo earned 500 total points
ID: 11783041
Hi

The following function is something I have been using for a while... cant remember where i found it now. It Starts at the root of the Active Directory and goes from there so it wont matter where the user is... he or she will be found :)

Used in conjunction with the information in the links from dlwyatt82 it might get you started

Bit to pay attention to is sAttribsToReturn parameter as this is the field that will be returned if the user is found ( i believe cn is equivalent to RDN)

' This function returns the users email address if found
Function get_Info(strName)

    ' Create ADO connection object for Active Directory
    Set oConn = CreateObject("ADODB.Connection")
    oConn.Provider = "ADsDSOObject"
    oConn.Open "Active Directory Provider"
    Set oCommand = CreateObject("ADODB.Command")
    oCommand.ActiveConnection = oConn
   
    ' Get the ADsPath for the domain to search.
    Set oRoot = GetObject("LDAP://rootDSE")
    sDomain = oRoot.Get("defaultNamingContext")
    Set oDomain = GetObject("LDAP://" & sDomain)
   
    ' Build the ADsPath element of the commandtext
    sADsPath = "<" & oDomain.ADsPath & ">"

    ' Build the filter element of the commandtext
    If (strName = "") Then
        sFilter = "(&(objectCategory=person)(objectClass=user))"
    Else
        sFilter = "(&(objectCategory=person)(objectClass=user)(sAMAccountName=" & strName & "))"
    End If
 
    ' Build the returned attributes element of the commandtext.
    sAttribsToReturn = "cn"
 
    ' Build the depth element of the commandtext.
    sDepth = "subTree"
    oCommand.CommandText = sADsPath & ";" & sFilter & ";" & sAttribsToReturn & ";" & sDepth

    ' Execute the query.
    Set oRS = oCommand.Execute
     
    ' If a record is found then return the email address
    If Not oRS.EOF Then
      get_Email = oRS.Fields(0).Value
    End If
   
    ' Tidy up
    oRS.Close
    Set oRS = Nothing
    Set oDomain = Nothing
    Set oRoot = Nothing
    Set oCommand = Nothing
    Set oConn = Nothing
   
End Function

HTH

Scott
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
This article will show you step-by-step instructions to build your own NTP CentOS server.  The network diagram shows the best practice to setup the NTP server farm for redundancy.  This article also serves as your NTP server documentation.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

879 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question