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
Post a Comment