小编Cas*_*spi的帖子

如何从 C# 中的 Active Directory 用户获取所有属性

我一直在寻找一种使用 C# 代码的解决方案,该解决方案可以查询 Active Directory 用户已注册的所有属性,无论它们是否具有 NULL 值。这些属性通过域服务器上 ADSI Edit 中用户属性中的“属性编辑器”选项卡可见。

ADSI 编辑中的 AD 用户属性

我需要动态检索这些属性,这意味着我可能无法通过 MSDN 上的 ADSI 文档可靠地获取这些属性名称,因为并非所有这些属性都可能是特定于用户对象的:https : //msdn.microsoft.com/en -us/library/ms675090(v=vs.85).aspx

这是我到目前为止所尝试的,但只得到了用户对象的一小部分属性:

  1. PS 命令Get-ADUser -Identity administrator -Properties:这检索了很大一部分属性,但不是几乎所有属性,我不知道在此命令期间调用了哪些 .NET 类和方法,因为TypeName = Microsoft.ActiveDirectory.Management.ADUser在 .NET 框架中不存在。如何在 PS 中查看 .NET 中使用的特定方法?

  2. C# 调用此方法:

    public bool GetUserAttributes(out List<string> userAttributes, string userName)
    {
        userAttributes = new List<string>();
        var valueReturn = false;
    
        try
        {
            const string pathNameDomain = "LDAP://test.local";
    
            var directoryEntry = new DirectoryEntry(pathNameDomain);
    
            var directorySearcher = new DirectorySearcher(directoryEntry)
            { …
    Run Code Online (Sandbox Code Playgroud)

c# powershell attributes ldap active-directory

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

active-directory ×1

attributes ×1

c# ×1

ldap ×1

powershell ×1