Closed kirkfranklin-alameda closed 2 years ago
Tried without success: php artisan ldap:import users --filter "(objectclass=person)" php artisan ldap:import users --filter "(objectClass=organizationalPerson)" php artisan ldap:import users --filter "(ou=City Clerk)"
This works: php artisan ldap:import users --filter "(cn=Ashley Zieba)"
Hi @kirkfranklin-alameda,
OU's are not attributes on objects. They are apart of the users distinguished name, as they are used to indicate hierarchy in the directory. This filter should work for you (though I'd recommend using a model scope instead).
Note: We're using a contains operation here via the asterisk (*) operator below. We must also escape equals (=) and commas (,) with a backslash inside of LDAP filters so that they may be parsed correctly).
--filter "(distinguishedName=*ou\=City Clerk*)"
I get an LdapRecordException error
λ php artisan ldap:import users --filter "(distinguishedName=*ou\=City Clerk*)"
LdapRecord\LdapRecordException
ldap_search(): Search: Bad search filter
at C:\inetpub\intranet\vendor\directorytree\ldaprecord\src\LdapRecordException.php:26
22▕ * @return $this
23▕ */
24▕ public static function withDetailedError(Exception $e, DetailedError $error = null)
25▕ {
➜ 26▕ return (new static($e->getMessage(), $e->getCode(), $e))->setDetailedError($error);
27▕ }
28▕
29▕ /**
30▕ * Set the detailed error.
1 C:\inetpub\intranet\vendor\directorytree\ldaprecord\src\HandlesConnection.php:184
LdapRecord\LdapRecordException::withDetailedError()
2 C:\inetpub\intranet\vendor\directorytree\ldaprecord\src\Ldap.php:235
ErrorException::("ldap_search(): Search: Bad search filter")
C:\inetpub\the-anchor (main -> origin)
Try a double backslash to escape the equals in the filter. 👍
With double backslash = "There were no users found to import."
php artisan ldap:import users --filter "(distinguishedName=*ou\\=City Clerk*)"
Discussed in https://github.com/DirectoryTree/LdapRecord-Laravel/discussions/430