I’ve been trying to read and set the departmentNumber property for a DirectoryEntry object using C#, but I always have the problem that using ADSI Edit I cannot see that anything in this entry was changed.
Approaches I’ve tried so far include:
directoryEntry.Properties["departmentNumber"].Value = new object[]{ "SomeContent" };
and
directoryEntry.InvokeSet("departmentNumber", new object[]{ "SomeContent" };
and
directoryEntry.Invoke("PutEx", new object[]{ 2, "departmentNumber", new object[]{"SomeContent"}});
and
directoryEntry.Invoke("Put", new object[]{ "departmentNumber", "SomeContent" });
Update
All of the above followed by directoryEntry.CommitChanges();.
No matter what I try, I do (with some of the examples above) get results in terms of being able to read the value again using corresponding code, but whenever I use the ADSI-Editor and look at the properties of the user, I cannot see that departmentNumber contains any data.
If I set the property to a certain value using ADSI-Editor, I also cannot query that particular value via C#, but what I can do is to use a very simple VB script as below:
Set objUser = GetObject("LDAP://CN=........")
objUser.GetInfo
objUser.PutEx 2, "departmentNumber", Array("SomeContent")
This does change the value of the property that I can see in the ADSI-Editor, but again, using C# I cannot read it.
What is the problem here, and why does it look as if there are two different “departmentNumber” properties? Despite trying to find someone with the same problem I didn’t come up with any answers or even pointers in the right direction, so any help is greatly appreciated. Please also ask in case you need more information.
You just forgot to commit changes. It’s necessary usin ADSI. Here is an example of a user création and modification :