【发布时间】:2014-10-20 11:25:26
【问题描述】:
我正在尝试使用要绑定的一组特定凭据连接到一些独立的 LDAP 存储(ADAM - Active Directory 应用程序模式),但无法找到最好的方法。这是一个我希望能起作用的例子:
$ldapHost = New-Object System.DirectoryServices.DirectoryEntry("LDAP://{serverip}:{port}/dc=acme,dc=com","cn=myuser,dc=acme,dc=com","myPassw0rd")
$ldapQuery = New-Object System.DirectoryServices.DirectorySearcher
$ldapQuery.SearchRoot = $ldapHost
$ldapQuery.Filter = "(objectclass=*)"
$ldapQuery.SearchScope = "Base"
$ldapQuery.FindAll()
这会让我着迷:
Exception calling "FindAll" with "0" argument(s): "A local error has occurred.
"
At line:1 char:19
+ $ldapQuery.FindAll <<<< ()
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
我也试过了:
$ldapHost = New-Object System.DirectoryServices.DirectoryEntry("LDAP://{myip}:{port}/dc=acme,dc=com")
$ldapHost.Username = "cn=myuser,dc=acme,dc=com"
结果:
The following exception occurred while retrieving member "Username": "The specified directory service attribute or valu
e does not exist.
"
At line:1 char:11
+ $ldapHost. <<<< Username = "cn=myuser,DC=acme,dc=com"
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyAssignmentException
我已经尝试了过滤器等的一些变体。我可以找到的大多数文档只是假设我从同一目录中连接到 ldap/正在连接正确的用户进行查询。
如果你熟悉 Python 的 ldap 模块,我就是这样做的:
import ldap
ld = ldap.initialize("ldap://{myip}:{port}")
ld.bind_s("cn=myuser,dc=acme,dc=com","Passw0rd")
ld.search_s("dc=acme,dc=com",ldap.SCOPE_BASE,"objectclass=*")
关于如何解决这个问题的任何指示?我绝对可以通过各种 LDAP 客户端进行连接。我可能需要明确指定身份验证,但我不确定,因为关于从域外查询的信息非常少。
【问题讨论】:
标签: powershell active-directory ldap