Greetings,
I am building a ASPX UI that will allow a HR representative manage the AD
Organization. I have a class that wraps a lot of AD work and I do things
like change password and update the GAL with Business information. I have
been able to write the code to get list of Direct Reports for a given user,
no problem. However, I am having trouble with how to set the 'manager' of a
AD user. Is it a property or a invoke function?
My code is simple like this...
public void AddDirectReport ( string ManagerAlias, string UserAlias )
{
DirectoryEntry deManager = GetUser(Manager Alias);
DirectoryEntry deDirectReport = GetUser(UserAli as);
this.SetPropert y( deDirectReport, "manager", this.GetPropert y( deManager,
"dn" ) );
deManager.Close ();
deDirectReport. Close();
}
public void SetProperty(Dir ectoryEntry oDE, string PropertyName, string
PropertyValue)
{
//check if the value is valid, otherwise dont update
if(PropertyValu e !=string.Empty)
{
//check if the property exists before adding it to the list
if(oDE.Properti es.Contains(Pro pertyName))
{
oDE.Properties[PropertyName][0]=PropertyValue;
oDE.CommitChang es();
}
else
{
oDE.Properties[PropertyName].Add(PropertyVa lue);
oDE.CommitChang es();
}
}
}
I have tried passing just the user alias instead of the Dn, and I get a
'Constrain violation error'. The code above, actually does not throw an
error, but it does not add the Manager either. Of course, GetUser() and
SetProperty() and GetProperty() are other members of the class to get the
Directory Entry of a user.
I have tried passing an empty string as the property value to try to remove
an already established Manager, but does not seem to work. The account that
makes the AD connection is a domain admin so it has rights..plus my other AD
code is running fine with this account on my staging environment. I have
waited 15 min to see if DC has been replicated, but no change to the AD
users I am testing with.
I have found example code using VB and ADSI calls, but C# and
DirectoryServic e namespace is scarce. The VB stuff looks like I am doing
the correct calls, but maybe I am missing something.
Anyone have experience in doing this with C# will help me greatly.
Thanx
Micah