用于列出Active Directory中的用户的程序 [英] Program to list the users in the Active Directory
本文介绍了用于列出Active Directory中的用户的程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我有程序会列出Active Directory中的用户。我创建了一个DirectorySearcher对象,我正在传递域的连接字符串。 />
DirectorySearcher dssearch = new DirectorySearcher(连接);
连接值为ldap://example.net。
但是一旦编译器点击上面一行,它就不会检索任何值。
Hi
I have program which would list the users in the Active Directory.I have created a DirectorySearcher object to which I'm passing the connection string of the domain.
DirectorySearcher dssearch = new DirectorySearcher(connection);
connection value is ldap://example.net.
But as soon as the compiler hits the above line, its not retrieving any values.
推荐答案
static void Main(string[] args)
{
string groupName = "Domain Users";
string domainName = "";
PrincipalContext ctx = new PrincipalContext(ContextType.Domain, domainName);
GroupPrincipal grp = GroupPrincipal.FindByIdentity(ctx, IdentityType.SamAccountName, groupName);
if (grp != null)
{
foreach (Principal p in grp.GetMembers(false))
{
Console.WriteLine(p.SamAccountName + " - " + p.DisplayName);
}
grp.Dispose();
ctx.Dispose();
Console.ReadLine();
}
else
{
Console.WriteLine("\nWe did not find that group in that domain, perhaps the group resides in a different domain?");
Console.ReadLine();
}
}
原始答案:获取C#中的Active Directory用户列表 [ ^ ]
这篇关于用于列出Active Directory中的用户的程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文