• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 291
  • Last Modified:

Full name of user out of Active Directory

I am trying to get the full name of a user (Jeff Reed) by using the login name of (jreed).  The server name is Crash1 @ and the domain is Test.com as seen below.  I have tried this ten different ways and can not get “Jeff Reed” out of it.  Yes, Jeff Reed actually exists in Active Directory and his login is jreed.  Where have I gone wrong and how do I get this up and running?

My.User.Name.ToString returns “jreed”


Private Function GetFullName(ByVal pName As String) As String
        Dim domainEntry As DirectoryEntry
        Dim searcher As DirectorySearcher
        Dim results As DirectoryServices.SearchResultCollection
        Dim fullName As String = Nothing
        Dim principleName As String = Nothing

        domainEntry = New DirectoryEntry("LDAP://Test.com")
        searcher = New DirectorySearcher(domainEntry, "userprinciplename = " + pName)
        results = searcher.FindAll()
        If (results.Count > 0) Then
            fullName = results(0).GetDirectoryEntry.Properties("givenName").Value.ToString & vbNewLine & _
        End If
        Return Name
End Function
  • 2
1 Solution
 Dim User As IADsUser
 Dim dirEntry As System.DirectoryServices.DirectoryEntry

dirEntry = New System.DirectoryServices.DirectoryEntry("WinNT://test.com/jreed,user")

User = CType(dirEntry.NativeObject(), IADsUser)

YOU WILL NEED TO ADD A REFERENCE TO THE Active DS Type Library for it to pickup the IADsUser Class

It would be fairier to say they cant be bothered to mark the question as answered, and hence not cost themselves any points.

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now