如何在GroupPrincipal上设置ManagedBy属性

mic*_*mus 6 c# directoryservices active-directory

我正在使用中的GroupPrincipal类创建和更新Active Directory中的组System.DirectoryServices.AccountManagement.在创建和更新时,我还需要能够在AD管理控制台的组属性ManagedByManaged By选项卡中设置您能够设置的属性.

可以以编程方式完成吗?

mar*_*c_s 8

不幸的是,你不能直接这样做 - 但你可以访问底层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();
}
Run Code Online (Sandbox Code Playgroud)