英文:
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>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论