如何在 C# 中获取 Active Directory 的类列表

How to get list of classes of an Active Directory in C#(如何在 C# 中获取 Active Directory 的类列表)
本文介绍了如何在 C# 中获取 Active Directory 的类列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在尝试获取 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?

推荐答案

如何获取 Active Directory 中存在的所有类?

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 成员来自 MSDN,了解更多详情.

Please refer to ReadOnlyActiveDirectorySchemaClassCollection Members from MSDN for more detail.

这篇关于如何在 C# 中获取 Active Directory 的类列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

What#39;s the difference between retrieving WindowsPrincipal from WindowsIdentity and Thread.CurrentPrincipal?(从 WindowsIdentity 和 Thread.CurrentPrincipal 检索 WindowsPrincipal 之间有什么区别?)
How do I find a user#39;s Active Directory display name in a C# web application?(如何在 C# Web 应用程序中查找用户的 Active Directory 显示名称?)
How can I authenticate against Active Directory in Nancy?(如何在 Nancy 中对 Active Directory 进行身份验证?)
How to get a username in Active Directory from a display name in C#?(如何从 C# 中的显示名称获取 Active Directory 中的用户名?)
Working with DirectoryServices in ASP.NET Core(在 ASP.NET Core 中使用 DirectoryServices)
Create Active Directory user in .NET (C#)(在 .NET (C#) 中创建 Active Directory 用户)