Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Finding Users RDN

Posted on 2004-08-11
2
Medium Priority
?
350 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 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

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…
Are you an Exchange administrator employed with an organization? And, have you encountered a corrupt Exchange database due to which you are not able to open its EDB file. This article will explain all the steps to repair corrupt Exchange database.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

688 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