View Full Version : Modify "managedBy" attribute - An Operations Error Occured


Ricky
I wanted to change the managedBy attribute for a group but
I keep on running on an operations error. Any help is
appreciated. Thanks!


This is the code for the method I'm using:


public static void SetGroupOwner(string Path, string User,
string Pwd, string Owner, string Group) {

DirectoryEntry ad =
GetDirectoryEntry("LDAP://server.domain.com", User, Pwd);
DirectorySearcher ds = new
DirectorySearcher(ad, string.Format("(&
(objectCategory=user)(name={0}))", Owner));
SearchResultCollection src =
ds.FindAll();
foreach(SearchResult sr in src)
{
try
{

DirectoryEntry usr = sr.GetDirectoryEntry();

DirectoryEntry de = GetDirectoryEntry(Group, User,
Pwd);

PropertyValueCollection pvc = de.Properties
["managedBy"];
pvc.Clear
();
pvc.Add
(GetProperty(usr, "distinguishedName"));

de.CommitChanges();
}
catch (Exception e) {

Console.WriteLine(e.Message);
}
}
}

Brian Desmond [MVP]
Ricky,

I don't think managedBy is a multivalued property. It's linked, though, so,
I'd just set it's value to the DN of the user, and then commit.

--
--
Brian Desmond
Windows Server MVP
desmondb@payton.cps.k12.il.us

Http://www.briandesmond.com


"Ricky" wrote in message
news:172e901c41840$c41153e0$a401280a@phx.gbl...
> I wanted to change the managedBy attribute for a group but
> I keep on running on an operations error. Any help is
> appreciated. Thanks!
>
>
> This is the code for the method I'm using:
>
>
> public static void SetGroupOwner(string Path, string User,
> string Pwd, string Owner, string Group) {
>
> DirectoryEntry ad =
> GetDirectoryEntry("LDAP://server.domain.com", User, Pwd);
> DirectorySearcher ds = new
> DirectorySearcher(ad, string.Format("(&
> (objectCategory=user)(name={0}))", Owner));
> SearchResultCollection src =
> ds.FindAll();
> foreach(SearchResult sr in src)
> {
> try
> {
>
> DirectoryEntry usr = sr.GetDirectoryEntry();
>
> DirectoryEntry de = GetDirectoryEntry(Group, User,
> Pwd);
>
> PropertyValueCollection pvc = de.Properties
> ["managedBy"];
> pvc.Clear
> ();
> pvc.Add
> (GetProperty(usr, "distinguishedName"));
>
> de.CommitChanges();
> }
> catch (Exception e) {
>
> Console.WriteLine(e.Message);
> }
> }
> }