Solved

Finding Users RDN

Posted on 2004-08-11
2
330 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 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

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Cursor typing problems 5 26
Cannot access port 443 4 573
Windows Explorer and WinZXip 4 496
Server 2012R2 Foundation and Server 2000 3 112
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…
Use of TCL script on Cisco devices:  - create file and merge it with running configuration to apply configuration changes
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now