查询AD LDS带有PowerShell和凭据
我可以使用 Windows 服务器中的 LDP 连接到我的 AD LDS 实例,但我很难使用同一服务器中的 PowerShell 连接/绑定和查询我的 AD LDS 实例。我无法找出正确的 PowerShell 语法。
以下是适用于 LDP 的连接参数/步骤:
服务器 = idm.mydomain.com
端口 = 636
选中 SSL 复选框
连接到 idm.mydomain.com 后,转到绑定
用户 = CN=canvas_service ,OU=用户,OU=基础设施支持,DC=idm,DC=mydomain,DC=com
密码= MyPassWord
绑定类型=简单绑定
这是我尝试过的PowerSHell
Import-Module ActiveDirectory
##############################################################################################
# Username, Password of an admin account for the AD LDS and the location of the AD LDS
$credUsername = 'CN=canvas_service,OU=Users,OU=Infrastructure Support,DC=idm,DC=mydomain,DC=com'
$credPassword = 'MyPassWord'
$server = 'idm.mydomain.com:636'
$userName = '*'
##############################################################################################
$cred = New-Object System.Management.Automation.PSCredential -ArgumentList `
@($credUsername,(ConvertTo-SecureString -String $credPassword -AsPlainText -Force))
$user = Get-ADUser -Filter {cn -eq $userName} -SearchBase "OU=Users,OU=Infrastructure Support,DC=idm,DC=mydomain,DC=com" -server $server -Credential $cred
结果 Get-ADUser :无法联系服务器。
我在网络上找不到任何包含凭据和 SSL 的 PowerShell 示例,可以为我指明正确的方向。非常感谢任何帮助。
I can connect to my AD LDS instance using LDP from a Windows server, but I am struggling to connect/bind and query my AD LDS instance with PowerShell from the same server. I can't figure out the correct PowerShell syntax.
Here are the connection parameters/steps that work for LDP:
Server = idm.mydomain.com
Port = 636
Check the SSL checkbox
Once connected to idm.mydomain.com, go to Bind
User = CN=canvas_service,OU=Users,OU=Infrastructure Support,DC=idm,DC=mydomain,DC=com
Password = MyPassWord
Bind type = Simple bind
Here is what I've tried in PowerSHell
Import-Module ActiveDirectory
##############################################################################################
# Username, Password of an admin account for the AD LDS and the location of the AD LDS
$credUsername = 'CN=canvas_service,OU=Users,OU=Infrastructure Support,DC=idm,DC=mydomain,DC=com'
$credPassword = 'MyPassWord'
$server = 'idm.mydomain.com:636'
$userName = '*'
##############################################################################################
$cred = New-Object System.Management.Automation.PSCredential -ArgumentList `
@($credUsername,(ConvertTo-SecureString -String $credPassword -AsPlainText -Force))
$user = Get-ADUser -Filter {cn -eq $userName} -SearchBase "OU=Users,OU=Infrastructure Support,DC=idm,DC=mydomain,DC=com" -server $server -Credential $cred
Result
Get-ADUser : Unable to contact the server.
I can't find any PowerShell examples on the web that include credentials and SSL that can point me in the corect direction. Any help greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如我的评论中所述,Active Directory 模块 使用 Active Directory Web 服务 作为协议,无法在此模块中使用 LDAP over SSL(简称 LDAPS)。您需要求助于
adsi
用于绑定,adsisearcher
进行查询。
有一段时间没有这样做了,所以下面的代码可能不起作用,但希望可以帮助您走上正轨。
As in my comments, the Active Directory Module uses Active Directory Web Services as protocol, it's not possible to use LDAP over SSL (LDAPS for short) with this Module. You would need to resort to
adsi
for binding andadsisearcher
for querying.Haven't done this in a while so it's likely that the code below won't work but hopefully can help you get on track.