Active directory

M

Mr. Bean

Hello,

I'm trying to retrieve the user's properties from Active Directory. I
was able to retrieve all the user properties, however, I wassnt able
to get the manager's user name. What I got was the path of the user
name : CN="Display Name", CN=myCompany,CN=COM..

Here is the

private string[] FindProps(String userAccount)
{
DirectoryEntry entry = new
DirectoryEntry("LDAP://mypc.mydomain.com");
String account = userAccount.Replace(@"mydomain\", "");
DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "(SAMAccountName=" + account + ")";
search.PropertiesToLoad.Add("displayName");
search.PropertiesToLoad.Add("mail");
search.PropertiesToLoad.Add("department");
search.PropertiesToLoad.Add("title");
search.PropertiesToLoad.Add("manager");
SearchResult result = search.FindOne();
string[] props = new string[10];
props[0] = result.Properties["displayname"][0].ToString();
props[1] = result.Properties["mail"][0].ToString();
props[2] = result.Properties["department"][0].ToString();
props[3] = result.Properties["manager"][0].ToString();
props[4] = result.Properties["title"][0].ToString();
return props;
} function i used to retrieve all the user props.
 
W

Willy Denoyette [MVP]

| Hello,
|
| I'm trying to retrieve the user's properties from Active Directory. I
| was able to retrieve all the user properties, however, I wassnt able
| to get the manager's user name. What I got was the path of the user
| name : CN="Display Name", CN=myCompany,CN=COM..
|
| Here is the
|
| private string[] FindProps(String userAccount)
| {
| DirectoryEntry entry = new
| DirectoryEntry("LDAP://mypc.mydomain.com");
| String account = userAccount.Replace(@"mydomain\", "");
| DirectorySearcher search = new DirectorySearcher(entry);
| search.Filter = "(SAMAccountName=" + account + ")";
| search.PropertiesToLoad.Add("displayName");
| search.PropertiesToLoad.Add("mail");
| search.PropertiesToLoad.Add("department");
| search.PropertiesToLoad.Add("title");
| search.PropertiesToLoad.Add("manager");
| SearchResult result = search.FindOne();
| string[] props = new string[10];
| props[0] = result.Properties["displayname"][0].ToString();
| props[1] = result.Properties["mail"][0].ToString();
| props[2] = result.Properties["department"][0].ToString();
| props[3] = result.Properties["manager"][0].ToString();
| props[4] = result.Properties["title"][0].ToString();
| return props;
| } function i used to retrieve all the user props.
|

This is normal, the Manager attribute is an Object(DS-DN) type attribute
that refers to the manager's user object. If you want the details of this
object you need to query it's properties.
I would suggest you to check the "Active Directory Schema" in the docs
before you start coding against the AD, it's fundamental that you understand
the formal definitions of the attributes of the objects you want to
retrieve.

Willy.
 
M

Marc Scheuner

I'm trying to retrieve the user's properties from Active Directory. I
was able to retrieve all the user properties, however, I wassnt able
to get the manager's user name. What I got was the path of the user
name : CN="Display Name", CN=myCompany,CN=COM..

Yes, that's the way it was designed. If you need details for the
manager, you will now need to grab his DN (distinguishedName), bind to
it, and retrieve that user's properties.

Marc
 
J

JimD

Mr. Bean said:
Hello,

I'm trying to retrieve the user's properties from Active Directory. I
was able to retrieve all the user properties, however, I wassnt able
to get the manager's user name. What I got was the path of the user
name : CN="Display Name", CN=myCompany,CN=COM..

Here is the

private string[] FindProps(String userAccount)
{
DirectoryEntry entry = new
DirectoryEntry("LDAP://mypc.mydomain.com");
String account = userAccount.Replace(@"mydomain\", "");
DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "(SAMAccountName=" + account + ")";
search.PropertiesToLoad.Add("displayName");
search.PropertiesToLoad.Add("mail");
search.PropertiesToLoad.Add("department");
search.PropertiesToLoad.Add("title");
search.PropertiesToLoad.Add("manager");
SearchResult result = search.FindOne();
string[] props = new string[10];
props[0] = result.Properties["displayname"][0].ToString();
props[1] = result.Properties["mail"][0].ToString();
props[2] = result.Properties["department"][0].ToString();
props[3] = result.Properties["manager"][0].ToString();
props[4] = result.Properties["title"][0].ToString();
return props;
} function i used to retrieve all the user props.

I attached an example of something I threw together to do a quick search
of AD.

Jim
--
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
There's no place like 127.0.0.1
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
JimD
Central FL, USA, Earth, Sol
 
M

Mr. Bean

COuld some one please tell me the exact function to use inorder to
retrieve the user name of the manager. ie what I need is to be able to
retrieve the user's manager in this form: domain\user.

Please include code sample
 
M

Mark Rae

COuld some one please tell me the exact function to use inorder to
retrieve the user name of the manager. ie what I need is to be able to
retrieve the user's manager in this form: domain\user.

Please include code sample

You've already received an explanation as to how to do this...
 
M

Mr. Bean

I didnt figure out how to confiugure the code knowing that I read the
previous posts
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top