Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrieve 'manager' from DirectoryServices.SearchResult

Status
Not open for further replies.

oticonaus

Technical User
Dec 16, 2003
96
AU
I am a newbie to .net and to Active DIrectory. I have cobbled together some code from various samples to retrieve a list of Names and Departments from Active Directory. This now works well.

I then query Active Directory again to determine the Manager of the selected Name. That almost works well, but what I get back from

DirectoryServices.SearchResult.Properties("Manager")(0)

gives me the full LDAP string. (CN=XXXX,OU=Users,OU=SYD - Sydney,OU=AU - Australia,......)

What I want is just the XXXX - not the whole string.

The same basic code worked when populating name and department into a combobox, so what could be the problem here?

Code:
        Dim dEntry As New DirectoryServices.DirectoryEntry("LDAP://abc.xyz.com/OU=SYD - Sydney,OU=AU - Australia,DC=xyz,DC=com")
        Dim dSearch As New System.DirectoryServices.DirectorySearcher(dEntry)
        Dim sManager As Object
        'define the filter
        dSearch.Filter = "(&(objectCategory=person)(&(objectClass=user)(name=" & Me.cmbName.SelectedItem & ")))"
        dSearch.SearchScope = DirectoryServices.SearchScope.Subtree

        'define the properties to retrieve
        dSearch.PropertiesToLoad.Add("Manager")
        dSearch.Sort.Direction = DirectoryServices.SortDirection.Ascending
        'dSearch.Sort.PropertyName = "Manager"

        'Define a collection to populate
        Dim cResult As DirectoryServices.SearchResultCollection

        'Excute the query
        cResult = dSearch.FindAll
        Dim oRes As DirectoryServices.SearchResult

        'query the collection and add the manager name to the textbox
        For Each oRes In cResult
            If Not (oRes.Properties("Manager")(0) Is Nothing) Then sManager = oRes.Properties("Manager")(0)
            Me.txtManager.Text = sManager
        Next
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top