查询AD LDS带有PowerShell和凭据

发布于 2025-01-19 01:30:06 字数 1366 浏览 0 评论 0原文

我可以使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情魔剑神 2025-01-26 01:30:06

正如我的评论中所述,Active Directory 模块 使用 Active Directory Web 服务 作为协议,无法在此模块中使用 LDAP over SSL(简称 LDAPS)。您需要求助于 adsi 用于绑定,adsisearcher进行查询。

有一段时间没有这样做了,所以下面的代码可能不起作用,但希望可以帮助您走上正轨。

$server = "idm.mydomain.com"
$port = 636
$ou = "OU=Users,OU=Infrastructure Support,DC=idm,DC=mydomain,DC=com"
$toSearch = "canvas_service"

# Below might require you to add `None` or `0` to the constructor for SimpleBind
# Beginning with .NET Framework 2.0, the default value is `Secure` or `1`.
$adsi = [adsi]::new("LDAP://${server}:${port}", "myUser", "myPasswordAsPlainText!!")
$searcher = [adsisearcher]::new($adsi)
$searcher.PropertiesToLoad.AddRange(@("samAccountName", "cn", "distinguishedName"))
$searcher.SearchRoot = $ou
$searcher.SearchScope = "SubTree"
$searcher.Filter = "(&(cn=$toSearch)(objectClass=user))"
$searcher.FindOne()

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 and adsisearcher 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.

$server = "idm.mydomain.com"
$port = 636
$ou = "OU=Users,OU=Infrastructure Support,DC=idm,DC=mydomain,DC=com"
$toSearch = "canvas_service"

# Below might require you to add `None` or `0` to the constructor for SimpleBind
# Beginning with .NET Framework 2.0, the default value is `Secure` or `1`.
$adsi = [adsi]::new("LDAP://${server}:${port}", "myUser", "myPasswordAsPlainText!!")
$searcher = [adsisearcher]::new($adsi)
$searcher.PropertiesToLoad.AddRange(@("samAccountName", "cn", "distinguishedName"))
$searcher.SearchRoot = $ou
$searcher.SearchScope = "SubTree"
$searcher.Filter = "(&(cn=$toSearch)(objectClass=user))"
$searcher.FindOne()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文