以上给出:
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<<<< () + CategoryInfo:NotSpecified:(:) [],MethodInvocationException + FullyQualifiedErrorId:DotNetMethodException
$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)
答案 0 :(得分:1)
您已设置$ldapSearch.Filter = $envFilter
,因此无需再次传入过滤器即可致电FindAll
。尝试将此作为最后一行代码,因为它仍然会内置过滤器:
$result = $ldapSearch.FindAll()
答案 1 :(得分:0)
我认为这是一个错字:
$ldapEntry = New-Object System.DirectoryServices.DirectoryEntry(
**$ldapUR**, $null, $null,
[System.DirectoryServices.AuthenticationTypes]::Anonymous
)
尝试
$ldapURI
而不是
$ldapUR