EDN Admin
Well-known member
Hi,
string _path = "LDAP://aap.intra.xyz.com/CN=Users,DC=aap,DC=intra,DC=xyz,DC=com";
DirectoryEntry entry = new DirectoryEntry(_path, username, pwd);
object obj = entry.NativeObject;
DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "(&(objectCategory=person)(objectClass=user)
(!userAccountControl:1.2.840.113556.1.4.803:=2))";
var propertiesToLoad = new[]
{
"SAMAccountName",
"displayName"
};
search.PropertiesToLoad.AddRange(propertiesToLoad);
foreach (SearchResult searchEntry in search.FindAll())
{
var userEntry = searchEntry.GetDirectoryEntry();
var samName = userEntry.Properties["SAMAccountName"].Value;
var mail = userEntry.Properties["mail"].Value;
var disName = userEntry.Properties["displayName"].Value;
}
To retrieve all the users in AD (above code) but it is returning the folder names like "intra" which is a folder in AD under which all the users are present.
Kindly suggest what the mistake I am doing ( connectionstring / code ).
Thanks in advance.
Sivananda Vanukuri
View the full article
string _path = "LDAP://aap.intra.xyz.com/CN=Users,DC=aap,DC=intra,DC=xyz,DC=com";
DirectoryEntry entry = new DirectoryEntry(_path, username, pwd);
object obj = entry.NativeObject;
DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "(&(objectCategory=person)(objectClass=user)
(!userAccountControl:1.2.840.113556.1.4.803:=2))";
var propertiesToLoad = new[]
{
"SAMAccountName",
"displayName"
};
search.PropertiesToLoad.AddRange(propertiesToLoad);
foreach (SearchResult searchEntry in search.FindAll())
{
var userEntry = searchEntry.GetDirectoryEntry();
var samName = userEntry.Properties["SAMAccountName"].Value;
var mail = userEntry.Properties["mail"].Value;
var disName = userEntry.Properties["displayName"].Value;
}
To retrieve all the users in AD (above code) but it is returning the folder names like "intra" which is a folder in AD under which all the users are present.
Kindly suggest what the mistake I am doing ( connectionstring / code ).
Thanks in advance.
Sivananda Vanukuri
View the full article