active directory - Moving AD user from OU to another using C# -


i'm writing code move ad user 1 ou ou. i've read many answers in stackoverflow , came following code:

            string usertobemoved = "someusername"; // username (login name) of user exists in ad         string sourceldappath = "ldap://ou=sourceou,dc=mydomainname,dc=com";         directoryentry sourceldapconnection = new directoryentry(sourceldappath, adusername, adpassword);                         directorysearcher search = new directorysearcher(sourceldapconnection)         {             searchscope = searchscope.subtree,             filter = "(&" +                 "(objectclass=user)" +                 "(samaccountname=" + usertobemoved + ")" +             ")"         };          search.propertiestoload.add("distinguishedname");          searchresult result = search.findone();          using (directoryentry userentry = result.getdirectoryentry())         {                                 if (userentry != null)             {                 string targetldappath = "ldap://ou=targetou,dc=mydomainname,dc=com";                 using (directoryentry targetldapconnection = new directoryentry(targetldappath, adusername, adpassword))                 {                                                 // line @ breaks                     userentry.moveto(targetldapconnection);                                             }                                     }         } 

the above code gives following error:

invalid dn syntax has been specified

the same question asked in article (active directory move user different ou) however, answer there not clear , code provided same code provided in question (which wrong)

any highly appreciated


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -