Moving an AD user from an OU to another OU

Viewed 9433

I want to move active directory user from one organization unit to another using C#.

I have referred below links

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

and tried below code, but it throws error

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);

Above code throws below error

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'
2 Answers

You don't need any credentials to pass I did the following

DirectoryEntry oDE= new DirectoryEntry(LDAP://" + "CN="xxx OU=xxxx,DC=xxxxxxx,DC=xxx");
DirectoryEntry de = new DirectoryEntry("LDAP://"+ "OU=xxxx,DC=xxxxxxx,DC=xxx");
oDE.MoveTo(de);
Related