locked
AD - Find users in AD group RRS feed

  • Question

  • User-1386562875 posted

    With the DirectorySearcher, I found a AD group.

    How can I find all the users in this AD group?

     

    Friday, October 2, 2009 4:29 AM

Answers

  • User-68639941 posted
    hi,
    below code searches based on login name
    //create instance fo the direcory searcher
    		DirectorySearcher deSearch = new DirectorySearcher(de);
    
    		//set the search filter
    		deSearch.SearchRoot = de;
    		deSearch.Filter = "(&(objectCategory=user)(samaccountname=" + accountName + "))";
    
    
    		//find the first instance
    		SearchResultCollection results = deSearch.FindAll();
    		if (results.Count > 0)
    		{
    			SearchResult sr = results[0];
    			ResultPropertyCollection myResultPropColl = sr.Properties;
    			ResultPropertyValueCollection rpvc = null;
    			if (sr.Properties.Contains("description"))
    			{
    				rpvc = myResultPropColl["description"];
    				return rpvc[0].ToString();
    			}
    		}


     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, October 3, 2009 12:06 AM