0

I'm working on a project using PHP Adldap2 Library (https://github.com/Adldap2/Adldap2) and I need to retrieve a list of sub-OUs within a specific OU from Active Directory.

That's what I tried:

$ad->search()
   ->whereEquals(
       ActiveDirectory::OBJECT_CATEGORY,
       ActiveDirectory::ORGANIZATIONAL_UNIT_LONG
   )
   ->whereEndsWith('dn', 'OU=myou,DC=mycompany,DC=com')
   ->get();

While the first filter works and retrieves all OUs, the second doesn't and returns an empty array. I also tried using 'distinguishedname' instead of 'dn' in whereEndsWith, with the same result.

How can this be done?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Bakanyaka
  • 11
  • 3

1 Answers1

1

After doing some research and experimentation I came up with this code:

$config = Adldap::getConfiguration();
$baseDn = new Adldap\Objects\DistinguishedName($config->getBaseDn());
$departmentsDn = $baseDn->addOu('myou');
$search = Adldap::search()->setDn($departmentsDn->get());
$entries = $search->whereEquals(ActiveDirectory::OBJECT_CATEGORY, ActiveDirectory::ORGANIZATIONAL_UNIT_LONG)->get();

I'm not sure if it is the best solution but it works.

PS: I'm using Laravel adldap facade that's why adldap calls are static.

Bakanyaka
  • 11
  • 3