按 sAMAccountName 和域进行 Active Directory LDAP 查询
如何通过 sAMAccountName 和域查询 LDAP 存储? Active Directory 或 LDAP 术语中命名的“域”属性是什么?
这就是我到目前为止所拥有的过滤器。 我希望能够在域中添加:
(&(objectCategory=Person)(sAMAccountName=BTYNDALL))
How do you do a query of an LDAP store by sAMAccountName and Domain? What is the "domain" property named in Active Directory or LDAP terms?
This is what I have for the filter so far. I'd like to be able to add in the domain:
(&(objectCategory=Person)(sAMAccountName=BTYNDALL))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
首先,修改搜索过滤器以仅查找用户而不查找联系人:
您可以通过连接到配置分区并枚举分区容器中的所有条目来枚举林的所有域。 抱歉,我现在没有任何 C# 代码,但这里是我过去使用过的一些 vbscript 代码:
从中您可以检索每个分区的名称和 dnsRoot:
First, modify your search filter to only look for users and not contacts:
You can enumerate all of the domains of a forest by connecting to the configuration partition and enumerating all the entries in the partitions container. Sorry I don't have any C# code right now but here is some vbscript code I've used in the past:
From that you can retrieve the name and dnsRoot of each partition:
您可以使用以下查询
登录名(Windows 2000 之前)等于 John 的用户
所有用户
启用的用户
禁用的用户
锁定的用户
You can use following queries
Users whose Logon Name(Pre-Windows 2000) is equal to John
All Users
Enabled Users
Disabled Users
LockedOut Users
搜索用户的最佳方式是
(sAMAccountType=805306368)
。或者对于禁用用户:
(&(sAMAccountType=805306368)(userAccountControl:1.2.840.113556.1.4.803:=2))
或者对于活跃用户:
(&(sAMAccountType=805306368 )(!(userAccountControl:1.2.840.113556.1.4.803:=2)))
我发现 LDAP 并没有想象中那么轻松。
还有常见 LDAP 查询的资源 - 尝试自己找到它们你会浪费宝贵的时间,而且肯定会犯错误。
关于域:在单个查询中这是不可能的,因为域是用户
distinguishedName
(DN
) 的一部分,在 Microsoft AD 上,无法通过部分匹配进行搜索。The best way of searching for users is
(sAMAccountType=805306368)
.Or for disabled users:
(&(sAMAccountType=805306368)(userAccountControl:1.2.840.113556.1.4.803:=2))
Or for active users:
(&(sAMAccountType=805306368)(!(userAccountControl:1.2.840.113556.1.4.803:=2)))
I find LDAP as not being so light at it was supposed to be.
Also resource for common LDAP queries - trying to find them yourself and you will lose precious time and definitely make mistakes.
Regarding domains: it's not possible in a single query because the domain is part of the user
distinguisedName
(DN
) which, on Microsoft AD, is not searchable by partial matching.“域”不是 LDAP 对象的属性。 它更像是存储对象的数据库的名称。
因此您必须连接到正确的数据库(用LDAP术语来说:“绑定到域/目录服务器”) 以便在该数据库中执行搜索。
绑定成功后,当前形状的查询就足够了。
顺便说一句:选择
“ObjectCategory=Person”
而不是“ObjectClass=user”
是一个不错的决定。 在AD中,前者是“索引属性”,性能优良,后者没有索引,速度稍慢。"Domain" is not a property of an LDAP object. It is more like the name of the database the object is stored in.
So you have to connect to the right database (in LDAP terms: "bind to the domain/directory server") in order to perform a search in that database.
Once you bound successfully, your query in it's current shape is all you need.
BTW: Choosing
"ObjectCategory=Person"
over"ObjectClass=user"
was a good decision. In AD, the former is an "indexed property" with excellent performance, the latter is not indexed and a tad slower.您必须在域中执行搜索:
http:// /msdn.microsoft.com/en-us/library/ms677934(VS.85).aspx
因此,基本上您应该绑定到一个域才能在该域内进行搜索。
You have to perform your search in the domain:
http://msdn.microsoft.com/en-us/library/ms677934(VS.85).aspx
So, basically your should bind to a domain in order to search inside this domain.
如果您使用的是 .NET,请使用 DirectorySearcher 类。 您可以将域作为字符串传递到构造函数中。
If you're using .NET, use the DirectorySearcher class. You can pass in your domain as a string into the constructor.
我编写了一个 C# 类,其中包含
但是,它不支持站点感知。
I have written a C# class incorporating
However, it is not Site-aware.