2016-06-03 5 views
1

Wie nehme ich einen Prinzipal und sehe, ob es eine Gruppe ist? oder dass es Mitglieder hat?AccountManagement ist Principal GroupPrincipal?

using(var ctx = new PrincipalContext(ContextType.Domain, "some.domain.com", "DC=some,DC=domain,DC=com")) 
{ 
    var group = GroupPrincipal.FindByIdentity(ctx, IdentityType.DistinguishedName, "some long distinguishedname"); 
    if(group != null) 
    { 
     var subgroups = group.GetMembers().Where(m => m.[IS A GROUP]) 
     foreach (var principal in group.GetMembers()) 
     { 
      Console.WriteLine(principal.DistinguishedName); 
     } 
    } 

} 
+0

denke ich, habe die Antwort gefunden: http://stackoverflow.com/questions/6354807/how-to-know-if-directoryentry-is-a-user-or-a-group –

Antwort

2

können Sie „convert“ die Principal die as Schlüsselwort - wenn es funktioniert, wenn das Objekt wirklich ein GroupPrincipal ist, können Sie einen gültigen Wert, sonst null bekommen:

var group = GroupPrincipal.FindByIdentity(ctx, 
              IdentityType.DistinguishedName, 
              "some long dn") as GroupPrincipal; 
                  ****************** 

if (group != null) 
{ 
    // now you *know* that it *IS* in fact a "GroupPrincipal" 
    ..... 
} 
Verwandte Themen