4 Haziran 2016 Cumartesi

GroupPrincipal Sınıfı

Giriş
Şu satırı dahil ederiz.
using System.DirectoryServices.AccountManagement.GroupPrincipal;
FindByIdentity metodu
Açılan PrincipalContext ile grupları sorgulamamızı sağlar.
Şöyle yaparız.
// find the group in question
GroupPrincipal grp = GroupPrincipal.FindByIdentity(pc, "YourGroupNameHere");
Şöyle yaparız.
string grpName = "SL-FILE-DAF-Agriculture-RID-PIFT";

var grp = GroupPrincipal.FindByIdentity(pc, IdentityType.SamAccountName,grpName);
GetMembers metodu
Şöyle yaparız.
PrincipalSearchResult<Principal> members = grp.GetMembers(true);
Her grup elemanını şöyle dolaşırız.
// iterate over members
foreach (Principal p in group.GetMembers())
{
  UserPrincipal up = p as UserPrincipal;

  if (up != null) 
  {
    Console.WriteLine("{0}: {1}", p.StructuralObjectClass, p.DisplayName);
    // do whatever you need to do with that user principal
  }
}
Her bir grup üyesinin hesap ismini şöyle alırız.
foreach (var member in members)
{
  Console.WriteLine(member.SamAccountName);
}
GetUnderlyingObject metodu
Şöyle yaparız.
DirectoryEntry entry = group.GetUnderlyingObject() as DirectoryEntry;

Hiç yorum yok:

Yorum Gönder