Moving computer objects in AD using VB .Net RRS feed

  • Question

  • Hello all,

    I am developing a simple program that allows IT staff to manipulate user account, computer objects, printers etc, from one central program. 

    I need help with how to move one AD object from one OU to another OU. I have a TreeView control that shows the AD objects. Ideally, they will right click an object (say, for example, a computer), click move which will show another dialog with another TreeView control from which they will be able to select the OU that the object is to me moved to (kind of like the way you can move objects in ADUC).

    Any help would be appreciated.


    Friday, May 26, 2017 11:49 AM

All replies

  • Have you looked at the MoveTo method?

    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Friday, May 26, 2017 1:29 PM
  • Hi The_Geek_99,

    Here is the sample that I find, please refer to.

        ' Bind to the object to be moved.
        Dim NewUser As New DirectoryEntry("LDAP://CN=User Name,OU=Sales,DC=fabrikam,DC=com")
        ' Use the MoveTo property to define the new container where you wish to move the object to.
        NewUser.MoveTo(New DirectoryEntry("LDAP://OU=HR,DC=fabrikam,DC=com"))
    Catch Exception1 As Exception
        Select Case Exception1.GetType().ToString()
            ' If InvalidOperationException is thrown, then the DirectoryEntry is not a container.
        Case "InvalidOperationException"
        Dim InvOpEx As New InvalidOperationException()
        ' Handle error, for example Console.WriteLine(InvOpEx.Message);
            ' If a COMException is thrown, then the following code can catch the text of the error.
            ' For more information about handling COM exceptions, see Handling Errors.
        Case "System.Runtime.InteropServices.COMException"
        Dim COMEx As System.Runtime.InteropServices.COMException = CType(Exception1, System.Runtime.InteropServices.COMException)
        ' Handle error, for example Console.WriteLine(COMEx.ErrorCode);
     End Select
        End Try

    Hope it is helpful to you.

    Best Regards,


    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

    Saturday, May 27, 2017 2:53 AM