For more information about ad programming, see adhelper. It seems that the method of assigning values to attributes of AD is incorrect.
The original method is similar to the following:
1 Public Static Void Setproperty (directoryentry de, String Propertyname, String Propertyvalue)
2 {
3 If (Propertyvalue ! = String . Empty | Propertyvalue ! = "" | Propertyvalue ! = Null )
4 {
5 If (De. properties. Contains (propertyname ))
6 {
7 De. properties [propertyname] [ 0 ] = Propertyvalue;
8 }
9 Else
10 {
11 De. properties [propertyname]. Add (propertyvalue );
12 }
13 }
14 }
However, in actual operations, you will find that sometimes the attribute we have assigned must be changed to a null value, then the method will not take effect. In addition, you will also find that the null value of propertyvalue is removed, and it will not pass, because no matter whether this attribute exists or not, you will report an error if you directly assign this attribute to null.
To assign a value to a null value, you can remove it. The following method is correct: 1 Public Static Void Setproperty (directoryentry entry, String Propertyname, String Propertyvalue)
2 {
3 If (Entry. properties. Contains (propertyname ))
4 {
5 If ( String . Isnullorempty (propertyvalue ))
6 {
7 Object O = Entry. properties [propertyname]. value;
8 Entry. properties [propertyname]. Remove (O );
9 }
10 Else
11 {
12 Entry. properties [propertyname] [ 0 ] = Propertyvalue;
13 }
14 }
15 Else
16 {
17 If ( ! String . Isnullorempty (propertyvalue ))
18 {
19 Entry. properties [propertyname]. Add (propertyvalue );
20 }
21 }
22 }