Guest User

Untitled

a guest
Oct 17th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.16 KB | None | 0 0
  1.         public static string GetGroupFromAD(string group)
  2.         {
  3.             DirectorySearcher search = new DirectorySearcher();
  4.             search.Filter = String.Format("(&(objectCategory=group)(cn={0}))", group);
  5.             search.PropertiesToLoad.Add("distinguishedName");
  6.             //SearchResultCollection results = search.FindAll();
  7.             SearchResult result = search.FindOne();
  8.  
  9.             if (result == null)
  10.             {
  11.                 throw new Exception("Could not find group in Active Direcroty");
  12.             }
  13.             else
  14.             {
  15.                 try
  16.                 {
  17.  
  18.                     return (string)result.Properties["distinguishedName"][0];
  19.                 }
  20.                 catch (Exception ex)
  21.                 {
  22.                     throw ex;
  23.                 }
  24.             }
  25.         }
  26.  
  27.         public static string GetMembersOfGroup(string objectPath)
  28.         {
  29.  
  30.             DirectoryEntry group = new DirectoryEntry("LDAP://" + objectPath);
  31.             foreach (object dn in group.Properties["member"])
  32.             {
  33.                 Console.WriteLine(dn);
  34.             }
  35.  
  36.             return "";
  37.         }
Add Comment
Please, Sign In to add comment