I have a small script to query a LDAP server
$domain = "LDAP://server-url:389/dc=dir,dc=cx,dc=com"
$auth = [System.DirectoryServices.AuthenticationTypes]::FastBind
$root = New-Object System.DirectoryServices.DirectoryEntry($domain, $Username, $Password, $auth)
$query = new-Object System.DirectoryServices.DirectorySearcher($root)
$query.Filter = "uid=myuser"
$objClass = $query.FindOne()
if (($objClass -eq $null) -or ($objClass.Count -eq 0))
{
write-Host "UID=myuser does not exist"
}
else
{
$properties = $objClass.Properties
foreach($field in $properties.GetEnumerator())
{
write-Host "$($field.name) => $($field.value)"
}
}
This works totally fine for some UIDs. For some however I get an exception on $query.findOne()
: Exception calling "FindOne" with "0" argument(s): "Exception from HRESULT: 0x8000500C"
Anyone has an idea where this could be coming from? I can search for these UIDs normally with any LDAP browser (e.g. Softerra) I also didn't see any special characters etc. in the fields for this user. I also tried findAll() but same error. If a user is not found, it goes correctly into the first if clause.
User contributions licensed under CC BY-SA 3.0