Skip to content

Core\Ldap\Ad::disabled

Returns a filter that matches the entries whose account is disabled. Use it with search, to find the accounts that cannot log in, for example before you clean them up.

The filter tests the bit with the value 2 in userAccountControl. It matches when that bit is set.

Good to know: Ad::enabled returns the opposite filter.

Return value

Returns Core\Ldap\Filter. A Core\Ldap\Filter.

Examples

The filter

<?nvs
// Shows the text of the filter for disabled accounts.
// This prints (userAccountControl:1.2.840.113556.1.4.803:=2).
echo Core\Ldap\Ad::disabled()->toString(), "\n";
Output
(userAccountControl:1.2.840.113556.1.4.803:=2)

Same as bit and

<?nvs
// Shows that `disabled` is the same filter as a bit test on `userAccountControl`.
var $disabled = Core\Ldap\Ad::disabled();
var $bit = Core\Ldap\Ad::bitAnd('userAccountControl', 2);
// The two texts are equal, so this prints same.
echo $disabled->toString() == $bit->toString() ? 'same' : 'different', "\n";
Output
same

Disabled by name

<?nvs
// Shows how to match the disabled users whose name starts with a text.
var $filter = Core\Ldap\Filter::all(
Core\Ldap\Filter::equals('objectClass', 'user'),
Core\Ldap\Filter::startsWith('sAMAccountName', 'temp'),
Core\Ldap\Ad::disabled(),
);
echo $filter->toString(), "\n";
Output
(&(objectClass=user)(sAMAccountName=temp*)(userAccountControl:1.2.840.113556.1.4.803:=2))