Solved

Get DisplayName for User's Manager from AD distinguishedName

Posted on 2016-10-04
2
42 Views
Last Modified: 2016-10-04
I'm using the below code to pull a number of attributes from a users AD profile. I can get the user's manager's distinguishedName, but I want to display the displayName. How can i either pull the displayName for the manager form AD, using either another directory query, or by splitting the distinguishedName into just the name, and getting rid of the rest of the string?

I get:
manager=CN=Bloggs\, Joe,OU=IT,OU=Users,DC=domain,DC=net
I want:
manager="Joe Bloggs" or "Bloggs, Joe"

Private Function GetUserProperties() As ADProperties
        Dim ADName As String = GetLogonName()
        Dim bSuccess As Boolean = False
        Dim dirEntry As DirectoryEntry = GetDirectoryEntry()
        Dim dirSearcher As DirectorySearcher = New DirectorySearcher(dirEntry)
        Dim waitTime As TimeSpan = New TimeSpan(0, 0, 0, 5, 0)
        dirSearcher.ClientTimeout = waitTime
        dirSearcher.Filter = ("(samAccountName=" & ADName & ")")
        dirSearcher.PropertiesToLoad.Add("manager")
        dirSearcher.SearchScope = SearchScope.Subtree
        Try
            Dim dirResult As SearchResult = dirSearcher.FindOne()
            bSuccess = Not (dirResult Is Nothing)
            If dirResult.GetDirectoryEntry.Properties("manager").Value Is Nothing Then
                GetUserProperties.manager = "<Not Set>"
            Else
                GetUserProperties.manager = (dirResult.Properties("manager")(0).ToString())
            End If
            bSuccess = True
        Catch ex As Exception
            bSuccess = False
            MsgBox("No Connection to the domain." & Environment.NewLine & "Please connect to corporate network & try again.", MsgBoxStyle.Critical, "Network Error #1")
            Application.Exit()
        End Try
    End Function

Open in new window

0
Comment
Question by:bjblackmore
[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
2 Comments
 

Accepted Solution

by:
bjblackmore earned 0 total points
ID: 41828176
Added the below looks to have worked:

            Using user As New DirectoryEntry("LDAP://" & distinguishedName)
                Dim strMgrDN As String = GetADProperty(user, "manager")
                If Not strMgrDN = "" Then
                    Using Manager As New DirectoryEntry("LDAP://" & strMgrDN)
                        managerDN.Text = GetADProperty(Manager, "displayName")
                    End Using
                Else
                    managerDN.Text = "Empty"
                End If
            End Using
0
 

Author Closing Comment

by:bjblackmore
ID: 41828253
Resolved on my own
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
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…

630 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