I'm attempting to find out if a user is an indirect member of a specific AD group. This is done from a Delphi XE5 program but, for clarity, I have written (and tested) my samples in PowerShell.
Unfortunately, I receive completely inconsistent results from my LDAP queries: the same query will sometime work fine and, sometimes, return that the user isn't member of the given group.
Here is a (powershell) sample of what I'm attempting:
get-aduser -LDAPFilter "(memberof:1.2.840.113556.1.4.1941:=CN=egaa_app,OU=Applications,OU=access,OU=groups,OU=xxx,DC=xxx,DC=xxx,DC=xxx)" -SearchBase "CN=usr-sgr,OU=expert1,OU=experts,OU=remoteusers,OU=users,OU=exogit,OU=xxx,DC=xxx,DC=xxx,DC=xxx"
The above command should return the user usr-sgr
object if it is directly or indirectly member of the AD groupegaa_app,OU=Applications,OU=access,OU=groups,OU=xxx,DC=xxx,DC=xxx,DC=xxx
Yet, when I run it once, I get an empty result. If I open the user in the AD MMC and update it somehow (in my case, I changed the user's "primary group" and then changed it back), the same query successfully returns the user object.
I have also attempted to use the "reverse" query (which check if a given group contains the user indirectly) and I witnessed the same behavior.
All this was done on a member server (Windows 2008 R2, patched), from within the same login session.