问题描述
我试图获取Active Directory的类和属性的列表.
I was trying get the list of classes and attributes of an Active Directory.
DirectoryEntry entry = new DirectoryEntry(
"LDAP://CN=Schema,CN=Configuration,DC=addomain,DC=com",
null, null, AuthenticationTypes.Secure);
ActiveDirectorySchema schema = ActiveDirectorySchema.GetCurrentSchema();
ActiveDirectorySchemaClass User = schema.FindClass("account");
foreach (ActiveDirectorySchemaProperty property in User.GetAllProperties())
{
Console.WriteLine("{0}", property.Name);
}
这将返回指定类的所有属性.如何获取Active Directory中存在的所有类?
This returns all the attributes of a specified class. How do I get all the classes that exist in Active Directory?
推荐答案
您需要修改所使用的相同代码.您需要找到该架构的所有类,如下所示.它会返回一个只读集合,其中包含ActiveDirectorySchemaClass
个对象,您需要阅读其各个项目.
You need to modify the same code which you've used. You need to find all classes for the schema, as I've shown below. It'd return a read-only collection that contains ActiveDirectorySchemaClass
objects, whose individual items you need to read.
DirectoryEntry entry = new DirectoryEntry(
"LDAP://CN=Schema,CN=Configuration,DC=addomain,DC=com",
null, null, AuthenticationTypes.Secure);
ActiveDirectorySchema schema = ActiveDirectorySchema.GetCurrentSchema();
// below code retrieves all Active Directory Domain Services classes in the schema.
ReadOnlyActiveDirectorySchemaClassCollection collection = schema.FindAllClasses();
// Now you can iterate over the collection Items.
foreach (ActiveDirectorySchemaClass schemaClass in collection)
{
foreach (ActiveDirectorySchemaProperty property in schemaClass.GetAllProperties())
{
Console.WriteLine("{0}", property.Name);
}
}
请参考 ReadOnlyActiveDirectorySchemaClassCollection
成员以获得更多详细信息.
Please refer to ReadOnlyActiveDirectorySchemaClassCollection
Members from MSDN for more detail.
这篇关于如何在C#中获取Active Directory的类列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!