Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static string GetGroupFromAD(string group)
- {
- DirectorySearcher search = new DirectorySearcher();
- search.Filter = String.Format("(&(objectCategory=group)(cn={0}))", group);
- search.PropertiesToLoad.Add("distinguishedName");
- //SearchResultCollection results = search.FindAll();
- SearchResult result = search.FindOne();
- if (result == null)
- {
- throw new Exception("Could not find group in Active Direcroty");
- }
- else
- {
- try
- {
- return (string)result.Properties["distinguishedName"][0];
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- }
- public static string GetMembersOfGroup(string objectPath)
- {
- DirectoryEntry group = new DirectoryEntry("LDAP://" + objectPath);
- foreach (object dn in group.Properties["member"])
- {
- Console.WriteLine(dn);
- }
- return "";
- }
Add Comment
Please, Sign In to add comment