Microsoft® Windows® 2000 Scripting Guide
Using the PutEx method with the clear control code (ADS_PROPERTY_CLEAR) applies to both single-valued and multivalued attributes. This control code deletes all existing entries. It is important for single-valued attributes because the Put method cannot completely clear an attribute. For example, you cannot specify NULL or "" for an attributes value when calling Put. In addition, while the following code will work to update the telephoneNumber attribute, the telephoneNumber attribute is not empty. Instead, it contains a single space:
objUser.Put "telephoneNumber", " "
To Active Directory, this means that the user actually has a phone number, regardless of whether it is valid phone number. If you search Active Directory for all users without a phone number (that is, all users for whom the telephoneNumber attribute is null), this user will not be included in the returned data.
Therefore, PutEx is the only method capable of completely clearing one or more entries from an attribute.
Listing 7.16 contains a script that demonstrates how to remove an entry in a single-valued attribute and all entries in a multivalued attribute. To carry out this task, the script performs the following steps:
Set the ADS_PROPERTY_CLEAR constant equal to the control code parameter used by the PutEx method to indicate the mode of modification (used on lines 6 and 7).
This control code removes entries from single-valued and multivalued attributes.
Bind to the user account object by using the GetObject function and the LDAP provider.
Use the PutEx method of IADs to remove the entry assigned to the initials single-valued attribute.
If no entry is assigned to the attribute, PutEx simply ignores the remove operation.
Use the PutEx method of IADs to remove any entries assigned to the otherTelephone attribute.
If no entries are assigned to the attribute, PutEx simply ignores the remove operation.
Commit the change to the user account object in the local property cache to Active Directory.
Listing 7.16 Removing Entries in Selected Single-valued and Multivalued Attributes
1 2 3 4 5 6 7 8 9
Const ADS_PROPERTY_CLEAR = 1 Set objUser = GetObject _ ("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com") objUser.PutEx ADS_PROPERTY_CLEAR, "initials", 0 objUser.PutEx ADS_PROPERTY_CLEAR, "otherTelephone", 0 objUser.SetInfo