사용자 memberof 그룹 목록을 가져올 수 있습니다. 나는 "Hey"가 포함 된 그룹 만 얻도록 그룹을 필터링하려고합니다. GroupHeyYou, GroupHeyThere, GroupYouKnow,사용자 그룹 필터링
GroupWhatThe 만 반환 GroupHeyYou 및 GroupHeyThere
이 제 기능입니다 : 뭔가 같은
public List<string> GetUserGroupMemberShip()
{
DirectoryEntry de = default(DirectoryEntry); //Binding object.
DirectorySearcher ds = default(DirectorySearcher); //Search object.
SearchResult sr = default(SearchResult);
List<string> groups = new List<string>();
string logonUserName = Environment.UserName;
string logonServer = (System.Environment.GetEnvironmentVariable("logonserver")).Remove(0, 2);
string activeDirectoryPath = "LDAP://" + logonServer + "." + System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().DomainName;
try
{
de = new DirectoryEntry(activeDirectoryPath);
ds = new DirectorySearcher(de, "(sAMAccountName=" + logonUserName + ")");
sr = ds.FindOne();
if (null != sr)
{
DirectoryEntry deUser = new DirectoryEntry(sr.Path);
object obGroups = deUser.Invoke("Groups");
foreach (object ob in (IEnumerable)obGroups)
{
DirectoryEntry deGroups = new DirectoryEntry(ob);
groups.Add(deGroups.Name);
}
}
}
catch (Exception)
{
return null;
}
return groups;
}
은 내가 어떻게 그렇게 할 필터를 사용할 수 있습니까?
다만 끝내면 디렉토리 엔트리의 & DirectorySearchers를 정리해야합니다. 그들은 관리되지 않는 리소스를 사용하므로 IDisposable을 구현합니다. –
이것은 DirectoryEntry와 함께 작업 한 첫 번째 시간입니다. DirectorySearcher는 너무 xD가 있지만 언급 해 주셔서 감사합니다. :) –