C# 分配多值属性';directReports&x27;使用System.DirectoryServices Active Directory API

C# 分配多值属性';directReports&x27;使用System.DirectoryServices Active Directory API,c#,active-directory,C#,Active Directory,我最初尝试将多个值作为directReports分配给Active Directory中的用户,是使用DirectoryEntry对象并按如下方式分配: DirectoryEntry de; //get it from somewhere de.Properties["directReports"].Value = object[] { "CN=user123,CN=Users,DC=DOMAIN,DC=xyz", "dn2", "dn3" }; de.CommitChanges(); //er

我最初尝试将多个值作为directReports分配给Active Directory中的用户,是使用DirectoryEntry对象并按如下方式分配:

DirectoryEntry de; //get it from somewhere
de.Properties["directReports"].Value = object[] { "CN=user123,CN=Users,DC=DOMAIN,DC=xyz", "dn2", "dn3" };
de.CommitChanges(); //error: contraint violation occurred
它对“manager”属性也不起作用

然后我开始使用UserPrincipal扩展方法(在后台使用DirectoryEntries,对吗?)

通过发送可分辨名称字符串来分配经理可以正常工作,但对直接下属不起作用。我仍然得到InvalidOperationException:发生了约束冲突。

我试着这样称呼它:

PrincipalContext pc = new PrincipalContext(ContextType.Domain, "mazen", user, pass);
UserPrincipalEx up = UserPrincipalEx.FindByIdentity(pc, IdentityType.SamAccountName, "moses");
var dns = new string[] { "CN=someone,CN=Users,DC=DOMAIN,DC=xyz", "CN=anotherone,CN=Users,DC=DOMAIN,DC=xyz" };
up.SetDirectReports(dns);

如何使用C#?

分配direct reports多值属性我相信
directReports
是Active Directory中的计算字段

如果您有10名员工与同一名经理在一起,则该经理的
directReports
属性将列出所有这10名员工


但是您不能自己直接设置该属性-您必须设置员工的
经理
属性,然后经理的
directReports
属性将由Active Directory自动设置“此属性包含直接向用户报告的用户列表。列为报告的用户是那些将property manager属性设置为此用户的用户。列表中的每一项都是对表示用户的对象的链接引用。“打开,但无法猜到您说了什么。感谢提醒。我猜在将directReports属性添加到条目之前(在将manager属性添加到下属上之后)会有延迟。”你知道多久了吗?你的回答让我很开心,非常感谢!!!
PrincipalContext pc = new PrincipalContext(ContextType.Domain, "mazen", user, pass);
UserPrincipalEx up = UserPrincipalEx.FindByIdentity(pc, IdentityType.SamAccountName, "moses");
var dns = new string[] { "CN=someone,CN=Users,DC=DOMAIN,DC=xyz", "CN=anotherone,CN=Users,DC=DOMAIN,DC=xyz" };
up.SetDirectReports(dns);