Solved

Finding Users RDN

Posted on 2004-08-11
2
344 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 125 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

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 describes how to import Lotus Notes Contacts into Outlook 2016, 2013, 2010 and 2007 etc. with a few manual steps. You can easily export and migrate Lotus Notes contacts into Microsoft Outlook without having to use any third party tools.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

623 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