如何在C#中获取具有登录工作站的活动目录用户?

huangapple go评论66阅读模式
英文:

How to get active directory users with logon workstation in c#

问题

我正在编写一个使用System.DirectoryServices来获取所有活动目录用户详细信息的代码,但是我没有找到一种获取每个用户的登录工作站(LogOnTo字段)的方法。

是否有获取用户工作站名称的方法?
感谢您的时间和分享您的知识。

英文:

I am writing a code for get all active directory user details with System.DirectoryServices but
i didn't find a way to get logon workstation (LogOnTo field) of each user.

Is there any way to get users workstation name?
thank you for your time and sharing your knowledge.

答案1

得分: 2

System.DirectoryServices中,您可以使用LDAP过滤器(&(objectCategory=User)(objectClass=person))来获取AD帐户详细信息,并且您可以尝试以下方法来获取用户工作站的名称:

DirectoryEntry ldapConnection = ADProvider.createDirectoryEntry(_Domain.DomainName, _Domain.DomainController, _Domain.Username, _Domain.Password, _targetOU);
DirectorySearcher search = new DirectorySearcher(ldapConnection, "(&(objectCategory=User)(objectClass=person))", null, SearchScope.OneLevel);
SearchResultCollection results = search.FindAll();
if (results != null)
{
    foreach (SearchResult sr in results)
    {
        sr.Properties["userworkstations"][0].ToString();
    }
}
英文:

in System.DirectoryServices you can user LDAP Filter (&(objectCategory=User)(objectClass=person)) to get AD Account Details
and you can try the folowing for get user workstation's name:

 DirectoryEntry ldapConnection = ADProvider.createDirectoryEntry(_Domain.DomainName, _Domain.DomainController, _Domain.Username, _Domain.Password, _targetOU);
                DirectorySearcher search = new DirectorySearcher(ldapConnection, "(&(objectCategory=User)(objectClass=person))", null, SearchScope.OneLevel);
                SearchResultCollection results = search.FindAll();
                if (results != null)
                {
                   
                    foreach (SearchResult sr in results)
                    {
                       sr.Properties["userworkstations"][0].ToString();
                    }
                }

</details>



huangapple
  • 本文由 发表于 2023年2月8日 15:25:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/75382518.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定