Search code examples
c#active-directorydirectoryservices

DirectoryEntry CommitChanges() not Committing Changes?


Before you outright close out this question as a duplicate, it's worth noting that the answer did not work.

So here's what I've tried thus far:

First attempt was to use .InvokeSet on the record:

adUser.InvokeSet("department", department);
adUser.CommitChanges();

Second attempt was to follow the answer on Calling commitChanges() does nothing in Active Directory? and try accessing the native object directly:

IADsTSUserEx nativeUser = (IADsTSUserEx)adUser.NativeObject;
nativeUser.Department = department;
adUser.CommitChanges();

Following up that with IADsUser instead.

Finally, I just tried setting it from the Value property:

adUser.Properties["department"].Value = department;
adUser.CommitChanges();

So I'm at a loss here. None of the above actually worked at saving changes. I have write access, and I'm not getting any exceptions. Am I just missing something, here? I'd like to think it's not a case of me trying to argue Select is Broken...

EDIT: See answer below.


Solution

  • It appears the problem was a case of my impatience.

    adUser.Properties["department"].Value = department;
    adUser.CommitChanges();
    

    did exactly what I needed; changes just hadn't replicated through all the AD servers at that point.