【问题标题】:Error when trying to do a search with Powershell towards LDAP尝试使用 Powershell 对 LDAP 进行搜索时出错
【发布时间】:2012-02-06 13:59:56
【问题描述】:

以上给出:

PS C:\EndurAutomation\powershell\bin> C:\EndurAutomation\powershell\bin\ets_update_constring.ps1 使用“0”参数调用“FindAll”的异常:“发生操作错误。 " 在 C:\EndurAutomation\powershell\bin\ets_update_constring.ps1:20 char:30 + $result = $ldapSearch.FindAll

$ldapDN = "dc=<masked>,dc=<masked>"
$ldapURI = "ldap://<masked>/$ldapDN"


$env = "sqlplus -S <masked> ``@env.sql > env.list"
Invoke-Expression $env
$envData = (Get-Content "env.list")

$envFilter = "(|"
foreach ($env in $envData) {
    $envFilter += "(cn=$env)"
}
$envFilter += ")"

$ldapEntry = New-Object System.DirectoryServices.DirectoryEntry($ldapUR, $null, $null,         [System.DirectoryServices.AuthenticationTypes]::Anonymous)
$ldapSearch = New-Object System.DirectoryServices.DirectorySearcher($ldapEntry)
$ldapSearch.PageSize = 1000
$ldapSearch.Filter = $envFilter

$result = $ldapSearch.FindAll($envFilter)

【问题讨论】:

    标签: powershell


    【解决方案1】:

    您已经设置了$ldapSearch.Filter = $envFilter,因此您无需通过再次传入过滤器来调用FindAll。尝试将此作为最后一行代码,因为它仍然会内置您的过滤器:

    $result = $ldapSearch.FindAll()
    

    【讨论】:

      【解决方案2】:

      我认为这是一个错字:

      $ldapEntry = New-Object System.DirectoryServices.DirectoryEntry(
              **$ldapUR**, $null, $null, 
              [System.DirectoryServices.AuthenticationTypes]::Anonymous
          )
      

      试试

      $ldapURI 
      

      而不是

      $ldapUR
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-08-07
        • 2023-03-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-04-27
        相关资源
        最近更新 更多