2013-10-01 8 views
1

J'essaie d'obtenir des informations (membres de groupes).Active Directory - comportement bizarre

Je reçois chaque fois que le message « Informations sur le domaine n'a pas pu être récupéré (1355) »

Pour obtenir les groupes, il a aidé à essayer seulement 2 fois. La première fois ne fonctionne pas, mais la deuxième fois m'apporte les groupes. Mais pour obtenir les membres d'un groupe, je n'ai pas de travail.

 PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "192.168.178.105:3268", "DC=ibcdev,DC=local", ContextOptions.Negotiate, "Administrator", "123"); 
     // define a "query-by-example" principal - here, we search for a GroupPrincipal 
     GroupPrincipal qbeGroup = new GroupPrincipal(ctx); 

     // create your principal searcher passing in the QBE principal  
     PrincipalSearcher srch = new PrincipalSearcher(qbeGroup); 

     // find all matches 
     try 
     { 
      var re2s = srch.FindAll().ToList(); 
     } 
     catch (Exception) 
     { 
     } 
     var res = srch.FindAll(); 
     foreach (Principal found in res) 
     { 
      Console.WriteLine(found.SamAccountName); 
      var group = GroupPrincipal.FindByIdentity(ctx, found.Name); 
      foreach (var user in group.Members) 
      { 
       Console.WriteLine(user.SamAccountName); 
      } 
     } 

Est-ce que quelqu'un sait ce que je fais mal?

Cordialement

Répondre

0

C'est ce que je l'utilise pour trouver un des membres de groupes dans un domaine:

public List<String> GetIDs(string domainName, string groupName) 
{ 
    using(PrincipalContext ctx = new PrincipalContext(ContextType.Domain, domainName)) 
    using(GroupPrincipal grp = GroupPrincipal.FindByIdentity(ctx, IdentityType.Name, groupName)) 
     return (from x in grp.GetMembers(true).AsParallel() select x.SamAccountName).ToList(); 
} 
+0

Merci, je vais essayer. – float