Introduction
The code given below will set the group owner of a group in Active Directory.
Background
To create the OwnerShip of a group in Active Directory you just need to call the Invoke function of the DirectoryEntry object for group. i.e.
dEntry.Invoke("Put", new object[] { "managedBy", "LDAP://CN=ravi.kant,DC=ADS,DC=COM"});
Using the code
A brief desciption of how to use the article or code. The class names, the methods and properties, any tricks or tips.
Blocks of code should be set as style "Formatted" like this:
public bool SetOwnerOfGroup(string ownerName, string groupLdapPath)
{
bool blSetGroup = false;
try
{
DirectoryEntry dEntryUser = new DirectoryEntry(LdapUtility.GetCongifValue("LDAPPath"));
DirectorySearcher dSearch = new DirectorySearcher(dEntryUser);
dSearch.SearchScope = System.DirectoryServices.SearchScope.Subtree;
string filter = "(&(objectCategory=user)(samaccountname=" + ownerName +
"))";
dSearch.Filter = filter;
SearchResult sr = dSearch.FindOne();
if (sr != null)
{
DirectoryEntry dEntryUserObj = sr.GetDirectoryEntry();
using (dEntryUserObj)
{
DirectoryEntry dEntry = new DirectoryEntry(groupLdapPath);
string path = dEntryUserObj.Path.Replace("LDAP://", "");
dEntry.Invoke("Put", new object[] { "managedBy", path });
dEntry.CommitChanges();
blSetGroup = true;
}
}
}
catch (Exception ex)
{
throw ex;
}
return blSetGroup;
}
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here