I'd like to increase speed for finding users in a query similar to this:
using (PrincipalContext pc = PrincipalContext(ContextType.Domain))
using (UserPrincipal up = new UserPrincipal(pc) { SamAccountName = $"*{search}*" })
using (PrincipalSearcher ps = PrincipalSearcher(up))
{
...
}
Currently, the query searches the whole directory, taking a very long time.
I'd like to constrain the context to a specific container, but I only now a single portion of this container.
So, for instance, from a full LDAP path like this: OU=a,OU=b,OU=c,dc=d,dc=e,dc=loc
I only have OU=b
.
How can I retrieve the full LDAP path for using it in the context
portion of the PrincipalContext
constructor by using a class from System.DirectoryServices.AccountManagement
having only a fraction of the path?