none
Active directory - Move user to cross forest using C# code RRS feed

  • Question

  • Hi,

    I have tried -

    DirectoryEntry theObjectToMove = new DirectoryEntry("LDAP://CN=R7,OU=TestMove,DC=connectivity,DC=lab", "connectivity\\Administrator", "Test123");
                DirectoryEntry theNewParent = new DirectoryEntry("LDAP://howrahDC01W16.howrah.lab/OU=MoveTest,DC=howrah,DC=lab", "HOWRAH\\Administrator", "Test@123");
                theObjectToMove.MoveTo(theNewParent);

    With above code i'm not able to achieve the move operation. Is there any other method/way to achieve it?

    Thanks in advance 


    Tuesday, August 7, 2018 7:30 AM

All replies

  • Hi

    Found this migration tool - https://msdn.microsoft.com/en-us/library/aa705991%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396

    As per this article it is possible to move objects across domains if certain requirements are met: https://technet.microsoft.com/en-us/library/ee198798.aspx?f=255&MSPPError=-2147217396


    Thanks,
    Vivek Bansod
    Blog | MSDN | LinkedIn
     

    Tuesday, August 7, 2018 7:50 AM
  • Thanks for the suggestion

    I have an application and wanted to do same through code.

    Tuesday, August 7, 2018 8:46 AM
  • Sure, your code looks ok however can you share more details like any error with your code and server role where you are running this code?

    Thanks,
    Vivek Bansod
    Blog | MSDN | LinkedIn
     

    Tuesday, August 7, 2018 9:00 AM
  • Hi abhijeet bhosale patil,

    Thank you for posting here.

    For your question, what error do you get from your code?

    The code format you used is correct. But maybe there is something wrong in your LADP parameter. Please refer to the code below without set the CN in new location.

    DirectoryEntry eLocation = new DirectoryEntry("LDAP://CN=Test User,OU=Users,OU=Development,DC=domain,DC=com", "domain\admin", "password");
    DirectoryEntry nLocation = new DirectoryEntry("LDAP://OU=Users,OU=QC,DC=domain,DC=com", "domain\admin", "password");
    eLocation.MoveTo(nLocation);
    nLocation.Close();
    eLocation.Close();

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, August 8, 2018 6:19 AM
    Moderator
  • I'm getting error - there is no such object found.

    Trust relationship is there between two forest. Also Administrator of source and target forest are added in Administrator group of source and Target domain.

    Executing application on source domain with Target directory entry -  with and without domain controller entry n LDAP Url.

    LDAP://OU=MoveTest,DC=howrah,DC=lab

    LDAP://172.16.25.5/OU=MoveTest,DC=howrah,DC=lab

    LDAP://howrahDC01W16.howrah.lab/OU=MoveTest,DC=howrah,DC=lab

    Able to do same through ADMT tool without any issue 

    Wednesday, August 8, 2018 10:06 AM
  • Hi abhijeet bhosale patil,

    Thank you for feedback.

    I guess maybe you do not have the permission to find the object or you use the wrong LADP.

    Please run as admin to test. If you do not get the same error, the code failed by the LADP. Try to use the LADP like the format in my code to test again.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, August 10, 2018 8:20 AM
    Moderator