Im using the Code from: How can I get a list of users from active directory? to get all User from my AD.
Now im trying to connect via LDAP to a Domain to get all Users from that Active Directory with the following changes:
using (PrincipalContext context = new PrincipalContext(ContextType.Domain, "192.168.1.100", "Username@testdomain.local", "Password"))
There are 2 different OUs at testdomain.local with Users but Im only getting the Users of one OU? I thought that gives me all Users from all OUs from AD?
If I use the following for my current AD Domain then I get all USers from all OUs?
using (PrincipalContext context = new PrincipalContext(ContextType.Domain, currentDomain))
Could that be a configuration problem on the other domain or is the Code not working with a LDAP Connection?
Thank you
UPDATE:
Code:
using (PrincipalContext context = new PrincipalContext(ContextType.Domain, "192.168.1.100", "Username@testdomain.local", "Password"))
{
using (PrincipalSearcher searcher = new PrincipalSearcher(new UserPrincipal(context)))
{
foreach (var result in searcher.FindAll())
{
DirectoryEntry de = result.GetUnderlyingObject() as DirectoryEntry;
de.Properties["samAccountName"].Value
}
catch (Exception c)
{
}
result.Dispose();
}
}