public static string[] GetDetailForUsers(string loginname)
{
var res = new List<string>();
string filter = "(&(objectCategory=user)(cn="+loginname+"))";
var searcher = new DirectorySearcher { SearchRoot = getRoot(), Filter = filter };
searcher.PropertiesToLoad.Clear();
searcher.PropertiesToLoad.Add("givenName");
searcher.PropertiesToLoad.Add("sn");
searcher.PageSize = 500;
try
{
using (SearchResultCollection results = searcher.FindAll())
{
foreach (SearchResult result in results)
{
int resultCount = result.Properties["givenName"].Count;
for (int c = 0; c < resultCount; c++)
{
res.Add(result.Properties["givenName"][c].ToString());
res.Add(result.Properties["sn"][c].ToString());
}
}
}
}
catch (Exception ex)
{
throw new ProviderException(ERROR_ACTIVEDIRECTORY_QUERY, ex);
}
return res.Count > 0 ? res.ToArray() : new string[0];
}
获取Active Directory里user的明细
最新推荐文章于 2022-02-23 15:02:25 发布