Bud*_*Joe 21 ldap active-directory ldap-query
如何通过sAMAccountName和Domain查询LDAP存储?在Active Directory或LDAP术语中命名的"域"属性是什么?
到目前为止,这就是我对过滤器的要求.我希望能够在域中添加:
(&(objectCategory=Person)(sAMAccountName=BTYNDALL))
Run Code Online (Sandbox Code Playgroud)
Dsc*_*duc 21
首先,修改您的搜索过滤器,仅查找用户而非联系人:
(&(objectCategory=person)(objectClass=user)(sAMAccountName=BTYNDALL))
Run Code Online (Sandbox Code Playgroud)
您可以通过连接到配置分区并枚举分区容器中的所有条目来枚举林的所有域.对不起,我现在没有任何C#代码,但这里是我过去使用的一些vbscript代码:
Set objRootDSE = GetObject("LDAP://RootDSE")
AdComm.Properties("Sort on") = "name"
AdComm.CommandText = "<LDAP://cn=Partitions," & _
objRootDSE.Get("ConfigurationNamingContext") & ">;" & _
"(&(objectcategory=crossRef)(systemFlags=3));" & _
"name,nCName,dnsRoot;onelevel"
set AdRs = AdComm.Execute
Run Code Online (Sandbox Code Playgroud)
从那里你可以检索每个分区的名称和dnsRoot:
AdRs.MoveFirst
With AdRs
While Not .EOF
dnsRoot = .Fields("dnsRoot")
Set objOption = Document.createElement("OPTION")
objOption.Text = dnsRoot(0)
objOption.Value = "LDAP://" & dnsRoot(0) & "/" & .Fields("nCName").Value
Domain.Add(objOption)
.MoveNext
Wend
End With
Run Code Online (Sandbox Code Playgroud)
kom*_*bsh 14
您可以使用以下查询
登录名(Pre-Windows 2000)等于John的用户
(&(objectCategory=person)(objectClass=user)(!sAMAccountType=805306370)(sAMAccountName=**John**))
Run Code Online (Sandbox Code Playgroud)
所有用户
(&(objectCategory=person)(objectClass=user)(!sAMAccountType=805306370))
Run Code Online (Sandbox Code Playgroud)
启用用户
(&(objectCategory=person)(objectClass=user)(!sAMAccountType=805306370)(!userAccountControl:1.2.840.113556.1.4.803:=2))
Run Code Online (Sandbox Code Playgroud)
残疾用户
(&(objectCategory=person)(objectClass=user)(!sAMAccountType=805306370)(userAccountControl:1.2.840.113556.1.4.803:=2))
Run Code Online (Sandbox Code Playgroud)
LockedOut用户
(&(objectCategory=person)(objectClass=user)(!sAMAccountType=805306370)(lockouttime>=1))
Run Code Online (Sandbox Code Playgroud)
搜索用户的最佳方式是.(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查询的资源- 试图自己找到它们,你会花费宝贵的时间并且肯定会犯错误.
关于域:在单个查询中不可能,因为域是user distinguisedName(DN)的一部分,在Microsoft AD上,不能通过部分匹配进行搜索.
"域"不是LDAP对象的属性.它更像是存储对象的数据库的名称.
因此,您必须连接到正确的数据库(在LDAP术语中:"绑定到域/目录服务器")才能在该数据库中执行搜索.
成功绑定后,您所需要的查询就是当前形状.
BTW:选择"ObjectCategory=Person"了"ObjectClass=user"是一个很好的决定.在AD中,前者是具有优异性能的"索引属性",后者没有索引且稍微慢一些.
| 归档时间: |
|
| 查看次数: |
221961 次 |
| 最近记录: |