【问题标题】:PowerShell OpenLDAP query returns nothingPowerShell OpenLDAP 查询不返回任何内容
【发布时间】:2019-09-03 07:56:02
【问题描述】:

我正在尝试检索 OpenLDAP 2.4 用户信息。 连接和绑定都可以,但请求什么也不返回。 经过一番调查,我发现有超过 150 000 条记录需要导入。我试图更改$ModelQuery 大小限制,但它并没有改变任何事情。 有什么好的方法来管理这个?

$HostName = "ldap.domain.com:389"
$user = 'user'

$Password = ConvertTo-SecureString 'password' -AsPlainText -Force
$pass = [PSCredential]::($user, $Password)

$null = [System.Reflection.Assembly]::LoadWithPartialName("System.DirectoryServices.Protocols")

$LDAPConnect = New-Object System.DirectoryServices.Protocols.LdapConnection "$HostName"
$LDAPConnect.AuthType = [System.DirectoryServices.Protocols.AuthType]::Basic
$LDAPConnect.SessionOptions.ProtocolVersion = 3

try {
    $ErrorActionPreference = 'Stop'
    $LDAPConnect.Credential = [PSCredential]::($user, $Password)
    $ErrorActionPreference = 'Continue'
} catch {
    throw "Erreur Bind LDAP - $($_.Exception.Message)"
}

Write-Verbose "Bind LDAP réussi" -Verbose

$BaseDn = 'ou=accounts,dc=domain,dc=com'
$Scope = [System.DirectoryServices.Protocols.SearchScope]::Subtree
$AttrList = $null
$Filter = '(property=staff)'
$ModelQuery = New-Object System.DirectoryServices.Protocols.SearchRequest -ArgumentList $BaseDn, $Filter, $Scope, $AttrList
$ModelQuery.SizeLimit = 10

try {
    $ErrorActionPreference = 'Stop'
    $ModelRequest = $LDAPConnect.SendRequest($ModelQuery)
    $ModelRequest.
    $ErrorActionPreference = 'Continue'
} catch {
    throw "Probleme de recherche sélection - $($_.Exception.Message)"
}

$ModelRequest.Entries | Export-Csv c:\res.csv

【问题讨论】:

  • [PSCredential]::($user, $Password) -> [PSCredential]::new($user, $Password)
  • oups...谢谢 Ansgar。此外,我删除了第一个。现在,我正在尝试设置一个数组或列表以将结果放入其中。希望它会返回值。我不确定修改 sizelimit 是否会是答案。

标签: powershell openldap


【解决方案1】:

只需添加变量@() 并将条目放入其中,然后在 csv 中输入管道

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-04-14
    • 1970-01-01
    • 2021-04-24
    • 2013-09-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多