Results 1 to 6 of 6

Thread: Need information on Active Directory

  1. #1
    Join Date
    Feb 2012
    Posts
    38

    Need information on Active Directory

    Hello I want help on Active Directory, I am trying build query Active Directory for every users on beneath present manager that is signed in. so I just wanted to create code for this, so can anyone help how to do this…. Thanks in advance.

  2. #2
    Join Date
    May 2011
    Posts
    105

    Re: Need information on Active Directory

    You can try this and I hope this will help you to solve your issue:

    Code:
    private static Collection<string> GetDirectReportsInternal(string ldapBase, string userDN, out long elapsedTime)
    {
        Collection<string> result = new Collection<string>();
    
        Stopwatch sw = new Stopwatch();
        sw.Start();
        string principalname = string.Empty;
    
        using (DirectoryEntry directoryEntry = new DirectoryEntry(ldapBase))
        {
            using (DirectorySearcher ds = new DirectorySearcher(directoryEntry))
            {
                ds.SearchScope = SearchScope.Subtree;
                ds.PropertiesToLoad.Clear();
                ds.PropertiesToLoad.Add("userPrincipalName");
                ds.PropertiesToLoad.Add("distinguishedName");
                ds.PageSize = 10;
                ds.ServerPageTimeLimit = TimeSpan.FromSeconds(2);
                ds.Filter = string.Format("(&(objectCategory=user)(manager={0}))",userDN);
    
                using (SearchResultCollection src = ds.FindAll())
                {
                    Collection<string> tmp = null;
                    long subElapsed = 0;
                    foreach (SearchResult sr in src)
                    {
                        result.Add((string)sr.Properties["userPrincipalName"][0]);
                        tmp = GetDirectReportsInternal(ldapBase, (string)sr.Properties["distinguishedName"][0], out subElapsed);
                        foreach (string s in tmp)
                        {
                        result.Add(s);
                        }
                    }
                }
              }
            }
        sw.Stop();
        elapsedTime = sw.ElapsedMilliseconds;
        return result;
    }

  3. #3
    Join Date
    Feb 2012
    Posts
    38

    Re: Need information on Active Directory

    Hello thanks for the replies but I am still hard work around with above code, first of all I am using VB.Net program to create code and I am looking for code or query Active Directory for all users on particular manager and after that just bind all query into gridview. I have looked at your code but this doesn’t helped me. Can anyone provide me example how this should work.

  4. #4
    Join Date
    May 2011
    Posts
    97

    Re: Need information on Active Directory

    Ok I will give example for your question, if you will want to sort for any candidate (for .e.g. Manager)
    Code:
     (&(objectCategory=User)(manager=CN=Raj\, Shrivastav))
    This will sort all manger’s name distinguished in the directory. So to do this you need to have manager's same accountname and you need to do distinguished name query for his/her before searching for list as manager. Here e.g. code to pull manager with distinguishedname and you can use this code on your function to load managed employees
    Code:
    Dim ManagerDNstr as string = GetManagerName("shrivastav.raj ")
    search.filter = "(&(objectCategory=User)(manager=" & ManagerDNstr & "))"
    hope this will help you to solve your issue.

  5. #5
    Join Date
    May 2011
    Posts
    102

    Re: Need information on Active Directory

    Ok I am using below and I hope his helps you to solve your issue:

    Code:
    Dim Etry As New System.DirectoryServices.DirectoryEntry("LDAP://domain")
            Dim Searcher As DirectorySearcher = New DirectorySearcher(Etry )
            Dim Results As SearchResultCollection
            Etry.Username = Nothing
            Etry.Password = Nothing
            With oSearcher
                .Filter = ("(&(manager=some name))")
            End With
            Searcher.PropertiesToLoad.Add("givenName")
            Searcher.PropertiesToLoad.Add("sn")
            Searcher.PropertiesToLoad.Add("sAMAccountname")
            Searcher.PropertiesToLoad.Add("physicalDeliveryOfficeName")
            Searcher.PropertiesToLoad.Add("department")
            Searcher.PropertiesToLoad.Add("manager")
            Dim Groupcol As ArrayList
            Groupcol = New ArrayList
            Results = Searcher.FindAll
    
            'Dim Members As Object = Searcher.FindAll
            If Results IsNot Nothing Then
                For Each Result In Results
                    Dim strFName As String = Result.Properties("givenName")(0).ToString
                    Dim strLName As String = Result.Properties("sn")(0).ToString
                    Groupcol.Add(strFName + " " + strLName)
                    'Groupcol.Add(Result.Properties("givenName")(0).ToString & " " & Result.Properties("sn")(0).ToString)
                Next
            End If
            Groupcol.Sort() '<<< Sort by ascending
            ddlReportsTo.DataSource = Groupcol(0) '<<< Bind to Dropdown List
            ddlReportsTo.DataBind()
            Searcher.Dispose()

  6. #6
    Join Date
    Nov 2008
    Posts
    159

    Re: Need information on Active Directory

    Getting the info to display will be the easy part. Since you have the data in a table you can use it just like any other data table and bind it to a data grid or drop down list. If you want to sort it, assert a dataset and insert the table to it then you can arrange it. If you need an example I can post some code tomorrow.

Similar Threads

  1. Replies: 4
    Last Post: 07-02-2011, 07:28 PM
  2. Replies: 5
    Last Post: 22-05-2010, 07:33 AM
  3. Need working information on Active Directory replication
    By Renau in forum Software Development
    Replies: 5
    Last Post: 08-02-2010, 08:59 AM
  4. Export user information Active Directory to openldap
    By MobilePhoneGuru in forum Networking & Security
    Replies: 3
    Last Post: 24-10-2009, 10:14 AM
  5. Active Directory VBScript to get user's OU information
    By MilesAway in forum Active Directory
    Replies: 3
    Last Post: 11-07-2009, 03:09 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,414,169.21595 seconds with 17 queries