Reputation: 10390
I'm trying to write an ldap filter which will retrieve the following users:
person
categoryuser
they must have either changed their password:
This way, I can see both users whose password is about to expire as well as users who have changed their password today.
I have been able to get the expiring users with this filter
$"(&(objectCategory=person)(objectClass=user)(pwdLastSet>={DateTime.Today.AddDays(-80).ToFileTime()})(pwdLastSet<={DateTime.Today.AddDays(-90).ToFileTime()})(!userAccountControl:1.2.840.113556.1.4.803:=2))"
But when I try to include users who changed their password today with
$"(&(objectCategory=person)(objectClass=user)(|(&(pwdLastSet>={DateTime.Today.AddDays(-80).ToFileTime()})(pwdLastSet<={DateTime.Today.AddDays(-90).ToFileTime()}))(&(pwdLastSet<={DateTime.Today.ToFileTime()})(pwdLastSet>={DateTime.Today.AddDays(-1).ToFileTime()})))(!userAccountControl:1.2.840.113556.1.4.803:=2))";
I ONLY get users who set their password today.
Can anyone help me by pointing in the right direction or giving general tips for building this type of filter (i.e. specifying 2 date ranges in a single filter)?
Upvotes: 0
Views: 296
Reputation: 10390
I managed to get my filter working and at the same time rearranged the code to make it more readable (I think):
private static string objPersonFilter = "objectCategory=person";
private static string classUserFilter = "objectClass=user";
private static string AccountEnabledFilter = "!userAccountControl:1.2.840.113556.1.4.803:=2";
private static string pwdExpiringMinimum = $"pwdLastSet<={DateTime.Today.AddDays(-80).ToFileTime()}";
private static string pwdExpiringMaximum = $"pwdLastSet>={DateTime.Today.AddDays(-90).ToFileTime()}";
private static string pwdChangedToday = $"pwdLastSet>={DateTime.Today.ToFileTime()}";
private string expiringPasswordFilter =
$"(&({objPersonFilter})({classUserFilter})({AccountEnabledFilter})(|({pwdChangedToday})(&({pwdExpiringMinimum})({pwdExpiringMaximum}))))";
Upvotes: 0