我有以下示例代码:
namespace DirectorySearcher
{
class Program
{
static void Main(string[] args)
{
using (var context = new PrincipalContext(ContextType.Domain, "bobo.net"))
{
using (var searcher = new PrincipalSearcher(new UserPrincipal(context) { Enabled = true }))
{
List<Principal> results = new List<Principal>();
results.AddRange(searcher.FindAll());
//foreach (var result in searcher.FindAll())
//{
//Console.WriteLine("displayName : " + result.DisplayName);
//Console.WriteLine("name : " + result.Name);
//Console.WriteLine();
//}
}
}
Console.WriteLine("Done");
Console.ReadLine();
}
}
}
如何仅将 result.DisaplayName 和 result.Name 分配给结果列表?
您可以将 PrincipalSearcher 配置为仅拉回这两个值以开始
就像您可以使用 PowerShell 一样,即:
Get-ADUser -Properties DisplayName,Name
谢谢