我正在使用System.DirectoryServices.AccountManagement中的GroupPrincipal类在Active Directory中创建和更新组。在创建和更新时,我还需要能够设置ManagedBy属性,您可以在AD管理控制台的groups属性的Managed By选项卡中设置该属性。
它可以通过编程来完成吗?
发布于 2010-07-20 19:32:38
不幸的是,你不能直接做到这一点--但你可以访问底层的DirectoryEntry并在那里完成:
PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "YOURDOMAIN");
UserPrincipal toBeModified = UserPrincipal.FindByIdentity(".....");
UserPrincipal manager = UserPrincipal.FindByIdentity(ctx, "......");
DirectoryEntry de = toBeModified.GetUnderlyingObject() as DirectoryEntry;
if (de != null)
{
de.Properties["managedBy"].Value = manager.DistinguishedName;
toBeModified.Save();
}发布于 2010-07-20 19:08:02
您可以扩展GroupPrincipal类并使用ExtensionSet方法提供ManagedBy属性。
发布于 2010-07-20 19:03:23
看看this page吧。这是c#中关于AD最好的教程之一。
一些应该可以工作的代码(未经测试):
string connectionPrefix = "LDAP://" + ouPath;
DirectoryEntry dirEntry = new DirectoryEntry(connectionPrefix);
DirectoryEntry newGroup = dirEntry.Children.Add
("CN=" + groupName, "group");
group.Properties["sAmAccountName"].Value = groupName;
newGroup.Properties["managedBy"].Value = managerDistinguishedName;
newGroup.CommitChanges();
dirEntry.Close();
newGroup.Close();https://stackoverflow.com/questions/3289215
复制相似问题