i am using ODBC to pull data from active directory to get the email for a particular username using the code below.
how can i use AD to pull all the usernames of peolel who report into a prticular manager?
i can transverse the org chart in outlook so im thinking i can do the same using AD…
ideas?
System.Data.OleDb.OleDbConnection con;
System.Data.OleDb.OleDbCommand cmd;
con = new System.Data.OleDb.OleDbConnection("Provider=ADsDSOObject;dsn=Active Directory Provider");
con.Open();
//Create a command object on this connection
string strSQL = "SELECT mail FROM 'LDAP://DC=amrs,DC=win,DC=ml,dc=COM' WHERE samaccountname = '" + UserName.Replace(@"AMRS\", "") + "'";
cmd = new System.Data.OleDb.OleDbCommand(strSQL, con);
try
{
return Convert.ToString ( cmd.ExecuteScalar() );
}
catch (System.Data.OleDb.OleDbException exc)
{
return "ERROR: " + exc.ToString();
}
finally
{
con.Close();
}
See if the manager attribute in AD is set? It should return you the distinguished name of the manager. You can then parse the string to figure out the samAccountName of the manager.
Then just repeat your search using the manager’s distinguished name.
Now if the manager attribute isn’t set….
Maybe search by department code, and then check the title of everyone in the department?
Might want to look into the Directory Services class.
This link gives you a basic tutorial on how to query AD