Nayef
Nayef

Reputation: 374

Move Object to an OU in Active Directory

I want to move a computer object to another OU I am connected to another domain and I always getting an exception of type ComException "A referral was returned from the server" and the object never move!

        try
        {
            //I get the exception here
            computerObject.MoveTo(new DirectoryEntry("LDAP://OU=someOU,OU=parentOU,DC=test,DC=com"));
            computerObject.CommitChanges();
        }
        catch (InvalidOperationException inOp)
        {
            //log 
        }
        catch (COMException comEx)
        {
            //log 
        }

        //joinPath.Close();
        finally
        {
            computerObject.Close();
        }

for troubleshooting I changed the code a little bit but again it doesn't work.

computerObject.MoveTo(new DirectoryEntry("LDAP://OU=someOU,OU=parentOU,DC=test,DC=com"),
                      "[email protected]","somepassowrd",AuthenticationTypes.Secure));

the new exception is of type ComException "Logon failure: unknown user name or bad password." I checked that there exists an OU in the active directory and I have enough permissions.

I followed Microsoft docs here https://msdn.microsoft.com/en-us/library/ms180856(v=vs.90).aspx and many stackoverflow questions.

Update: I am running my application in one domain and making changes in another domain, it might be the cause of the problem

Upvotes: 0

Views: 2956

Answers (3)

duescha
duescha

Reputation: 1

I had the same problem when I tried to move the OU connected from another domain. Adding the FQDN from domain to the path helped:

"LDAP://domainFqdn/OU=someOU,OU=parentOU,DC=test,DC=com"

Upvotes: 0

ganjeii
ganjeii

Reputation: 1178

You have an extra parenthesis in this method:

computerObject.MoveTo(new DirectoryEntry("LDAP://OU=someOU,OU=parentOU,DC=test,DC=com"),"[email protected]","somepassowrd",AuthenticationTypes.Secure));

it should be

computerObject.MoveTo(new DirectoryEntry("LDAP://OU=someOU,OU=parentOU,DC=test,DC=com","[email protected]", "somepassowrd", AuthenticationTypes.Secure));

This would certainly explain the exception, I'm surprised you debugger didn't catch it, unless you are writing it freehand, or maybe you mis-typed it into your question?

Upvotes: 0

Nayef
Nayef

Reputation: 374

I published my code in the same domain and it worked just fine

Upvotes: 0

Related Questions