将AD用户从一个OU移到另一个OU

Use*_*590 3 c# active-directory

我想使用C#将活动目录用户从一个组织单位移动到另一个组织单位。

我在下面提到了链接

  1. http://forums.asp.net/t/932664.aspx?移动+ an + AD + user + from + an + OU +到+ another + OU
  2. http://www.nullskull.com/q/10279930/to-move-a-user-from-one-ou-to-another-ou.aspx

并尝试下面的代码,但会引发错误

DirectoryEntry eLocation = new DirectoryEntry("LDAP://CN=Test User,OU=Users,OU=Development,DC=domain,DC=com");
DirectoryEntry nLocation = new DirectoryEntry("LDAP://OU=Users,OU=QC,DC=domain,DC=com");
eLocation.MoveTo(nLocation);
Run Code Online (Sandbox Code Playgroud)

上面的代码抛出错误

A referral was returned from the server.
Error code: -2147016661
Extended Error Message 0000202B: RefErr: DSID-0310082F, data 0, 1 access points
ref 1: 'domain.com'
Run Code Online (Sandbox Code Playgroud)

Use*_*590 5

我已经通过了如下的用户凭据,并且它像一种魅力一样工作。

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();
Run Code Online (Sandbox Code Playgroud)