none
find network group names RRS feed

  • Question

  • hi all,

    my server has an AD, under that it has 10 computers,

    i want to find out all the network group names(on that AD). is it possibile to find out the group names?

    Saturday, August 1, 2015 1:38 PM

Answers

  • By command line you can type "net group" to retrieve the list.

    There is an library System.DirectoryServices.dll, add reference to it:

    using System.DirectoryServices; 
    
    public class test
    {
    
        private void main()
        {
            foreach (string @group in GetGroups())
            {
                Debug.Print(@group);
            }
        }
    
        public List<string> GetGroups()
        {
            DirectoryEntry objADAM = default(DirectoryEntry);
            // Binding object. 
            DirectoryEntry objGroupEntry = default(DirectoryEntry);
            // Group Results. 
            DirectorySearcher objSearchADAM = default(DirectorySearcher);
            // Search object. 
            SearchResultCollection objSearchResults = default(SearchResultCollection);
            // Results collection. 
            string strPath = null;
            // Binding path. 
            List<string> result = new List<string>();
    
            // Construct the binding string. 
            strPath = "LDAP://stefanserver.stefannet.local";
            //Change to your ADserver 
    
            // Get the AD LDS object. 
            try
            {
                objADAM = new DirectoryEntry(strPath);
                objADAM.RefreshCache();
            }
            catch (Exception e)
            {
                throw e;
            }
    
            // Get search object, specify filter and scope, 
            // perform search. 
            try
            {
                objSearchADAM = new DirectorySearcher(objADAM);
                objSearchADAM.Filter = "(&(objectClass=group))";
                objSearchADAM.SearchScope = SearchScope.Subtree;
                objSearchResults = objSearchADAM.FindAll();
            }
            catch (Exception e)
            {
                throw e;
            }
    
            // Enumerate groups 
            try
            {
                if (objSearchResults.Count != 0)
                {
                    foreach (SearchResult objResult in objSearchResults)
                    {
                        objGroupEntry = objResult.GetDirectoryEntry;
                        result.Add(objGroupEntry.Name);
                    }
                }
                else
                {
                    throw new Exception("No groups found");
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
    
            return result;
        }
    
    }

    Sunday, August 2, 2015 2:36 AM

All replies

  • By command line you can type "net group" to retrieve the list.

    There is an library System.DirectoryServices.dll, add reference to it:

    using System.DirectoryServices; 
    
    public class test
    {
    
        private void main()
        {
            foreach (string @group in GetGroups())
            {
                Debug.Print(@group);
            }
        }
    
        public List<string> GetGroups()
        {
            DirectoryEntry objADAM = default(DirectoryEntry);
            // Binding object. 
            DirectoryEntry objGroupEntry = default(DirectoryEntry);
            // Group Results. 
            DirectorySearcher objSearchADAM = default(DirectorySearcher);
            // Search object. 
            SearchResultCollection objSearchResults = default(SearchResultCollection);
            // Results collection. 
            string strPath = null;
            // Binding path. 
            List<string> result = new List<string>();
    
            // Construct the binding string. 
            strPath = "LDAP://stefanserver.stefannet.local";
            //Change to your ADserver 
    
            // Get the AD LDS object. 
            try
            {
                objADAM = new DirectoryEntry(strPath);
                objADAM.RefreshCache();
            }
            catch (Exception e)
            {
                throw e;
            }
    
            // Get search object, specify filter and scope, 
            // perform search. 
            try
            {
                objSearchADAM = new DirectorySearcher(objADAM);
                objSearchADAM.Filter = "(&(objectClass=group))";
                objSearchADAM.SearchScope = SearchScope.Subtree;
                objSearchResults = objSearchADAM.FindAll();
            }
            catch (Exception e)
            {
                throw e;
            }
    
            // Enumerate groups 
            try
            {
                if (objSearchResults.Count != 0)
                {
                    foreach (SearchResult objResult in objSearchResults)
                    {
                        objGroupEntry = objResult.GetDirectoryEntry;
                        result.Add(objGroupEntry.Name);
                    }
                }
                else
                {
                    throw new Exception("No groups found");
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
    
            return result;
        }
    
    }

    Sunday, August 2, 2015 2:36 AM
  • thank you for your response.

    like wise, may i  know how do i add and remove users into groups?

    thank you,

    Sunday, August 2, 2015 2:08 PM
  • hi all,

    i want to get all Group Names from Active Directory and

    I want to get all Group Names which is associated with the user

    thank you

    Sunday, August 2, 2015 3:39 PM
  • In order to do this you can refer:

    https://msdn.microsoft.com/en-us/library/ms180904(v=vs.80).aspx
    https://msdn.microsoft.com/en-US/library/ms180905(v=vs.80).aspx

    Monday, August 3, 2015 1:28 AM
  • See this:

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/503dd284-9440-4e7c-8896-bcaf85148dfa/find-network-group-names?forum=netfxbcl#b20b0168-dc2f-47e2-b2f8-a3da227d5b23

    Monday, August 3, 2015 1:41 AM
  • thank you for your response.

    like wise, may i  know how do i add and remove users into groups?

    thank you,


    Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't ask several questions in the same thread.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, August 3, 2015 7:01 AM