Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Moving an object in Active Directory with c#

so the following code is supposed to move an object in active directory. I see what is going on here but i dont quite understand it. all i see is the old location and new location. I dont see how I actually grab the object. I have several objects in both locations, where does this code say what specific object is to be moved? I dont see where in the LDAP + objectLocation string that there is an object.

DirectoryEntry eLocation = new DirectoryEntry("LDAP://" + objectLocation);
DirectoryEntry nLocation = new DirectoryEntry("LDAP://" + newLocation);
string newName = eLocation.Name;
eLocation.MoveTo(nLocation, newName);
nLocation.Close();
eLocation.Close();
like image 383
Jon Avatar asked Dec 08 '22 22:12

Jon


1 Answers

Maybe this example will make it clearer:

DirectoryEntry theObjectToMove = new DirectoryEntry("LDAP://CN=jdoe,CN=Users,DC=acme,DC=com");
DirectoryEntry theNewParent = new DirectoryEntry("LDAP://OU=Something,DC=acme,DC=com");
theObjectToMove.MoveTo(theNewParent);

The overload of MoveTo with two parameters also specifies a new name for the object, and I think that in your example it's redundant.

like image 52
Paolo Tedesco Avatar answered Dec 28 '22 19:12

Paolo Tedesco