locked
Find Manage from AD RRS feed

  • Question

  • User847842510 posted

    I am trying to get the manager name of a particular user in active directory.  I have tried many outlets and still have yet to find one that works.  He is base code I am working off of:

            Dim UserAccount As String = "UserName"
            Dim Entry As DirectoryEntry = New DirectoryEntry("******", "******", "******")
            Dim Searcher As DirectorySearcher = New DirectorySearcher(Entry)
            Dim result As System.DirectoryServices.SearchResult
            Searcher.Filter = "(&(objectCategory=user)(samAccountName=" + UserAccount + "))"
            Searcher.PropertiesToLoad.Add("samAccountName")
            Searcher.PropertiesToLoad.Add("Manager")
            result = Searcher.FindOne()
    The big picture will be I want to send the manger an email so if I can get there login name / username or even email address in active directory, that would be even better.
    Thanks for any help.
     
    Tuesday, April 28, 2009 11:28 AM

Answers

  • User847842510 posted

    Nevermind.  I finally figured it all out.  Here is the final code:

     

            Dim UserAccount As String = "UserName"
            Dim Entry As DirectoryEntry = New DirectoryEntry("LDAP://*******", "*******", "******")
            Dim Searcher As DirectorySearcher = New DirectorySearcher(Entry)
            Dim result As System.DirectoryServices.SearchResult
            Searcher.Filter = "(&(objectCategory=user)(samAccountName=" + UserAccount + "))"
            Searcher.SearchScope = SearchScope.Subtree
            result = Searcher.FindOne()
    
            Dim ResultStr As String = result.Properties("Manager")(0)
    
            Dim ValuesArray As String() = ResultStr.Split(",")
    
    
            lblOutput.Text = ValuesArray(0).Replace("CN=", "")
     
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 28, 2009 12:39 PM

All replies

  • User847842510 posted

    I got it to display:

    "CN=Manger Name,OU=Department,OU=City,DC=Domain,DC=org"

    How can a just take the Manger name out of the string?

     New Code Here:

     

    1            Dim UserAccount As String = "UserName"
    2            Dim Entry As DirectoryEntry = New DirectoryEntry("LDAP://******", "******", "*****")
    3            Dim Searcher As DirectorySearcher = New DirectorySearcher(Entry)
    4            Dim result As System.DirectoryServices.SearchResult
    5            Searcher.Filter = "(&(objectCategory=user)(samAccountName=" + UserAccount + "))"
    6            Searcher.SearchScope = SearchScope.Subtree
    7            result = Searcher.FindOne()
    8    
    9            lblOutput.Text = result.Properties("Manager")(0)
    
     
    Tuesday, April 28, 2009 12:26 PM
  • User847842510 posted

    Nevermind.  I finally figured it all out.  Here is the final code:

     

            Dim UserAccount As String = "UserName"
            Dim Entry As DirectoryEntry = New DirectoryEntry("LDAP://*******", "*******", "******")
            Dim Searcher As DirectorySearcher = New DirectorySearcher(Entry)
            Dim result As System.DirectoryServices.SearchResult
            Searcher.Filter = "(&(objectCategory=user)(samAccountName=" + UserAccount + "))"
            Searcher.SearchScope = SearchScope.Subtree
            result = Searcher.FindOne()
    
            Dim ResultStr As String = result.Properties("Manager")(0)
    
            Dim ValuesArray As String() = ResultStr.Split(",")
    
    
            lblOutput.Text = ValuesArray(0).Replace("CN=", "")
     
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 28, 2009 12:39 PM