Recipe 15.10. Modifying an ObjectProblemYou want to modify one or more attributes of an object. SolutionThe following examples set the last name (sn) attribute for the jsmith user object. Using a graphical user interface
Using a command-line interfaceCreate an LDIF file called modify_object.ldf with the following contents: dn: cn=jsmith,cn=users,dc=rallencorp,dc=com changetype: modify add: sn sn: Smith - Then run the following command: > ldifde -v -i -f modify_object.ldf You can modify a limited number of object types with the dsmod command. Run dsmod /? from a command line for more details. Using VBScriptstrObjectDN = "cn=jsmith,cn=users,dc=rallencorp,dc=com" set objUser = GetObject("LDAP://" & strObjectDN) objUser.Put "sn", "Smith" objUser.SetInfo DiscussionUsing a graphical user interfaceIf the parent container of the object you want to modify has a lot of objects in it, you may want to add a new connection for the DN of the target object. This will be easier than trying to hunt through a container full of objects. You can do this by right-clicking ADSI Edit and selecting Connect to.... Under Connection Point, select Distinguished Name and enter the DN of the object. Using a command-line interfaceFor more on ldifde, see Recipe 15.15. As of the publication of this book, the only types of objects you can modify with dsmod are computer, contact, group, ou, server, quota, and user. Using VBScriptIf you need to do anything more than assign or replace a value for an attribute, you'll need to use the PutEx method instead of Put. PutEx allows for greater control in assigning multiple values, deleting specific values, and appending values. PutEx requires three parameters: an update flag, an attribute name, and an array of values to set or unset. The update flags are defined by the ADS_PROPERTY_OPERATION_ENUM collection and listed in Table 15-2.
Finally, SetInfo commits the change. If SetInfo is not called, the creation will not get committed to the domain controller. In the following example, each update flag is used while setting the otherTelephoneNumber attribute: strObjectDN = "cn=jsmith,cn=users,dc=rallencorp,dc=com" const ADS_PROPERTY_CLEAR = 1 const ADS_PROPERTY_UPDATE = 2 const ADS_PROPERTY_APPEND = 3 const ADS_PROPERTY_DELETE = 4 set objUser = GetObject("LDAP://" & strObjectDN) ' Add/Append two values objUser.PutEx ADS_PROPERTY_APPEND, "otherTelephoneNumber", _ Array("555-1212", "555-1213") objUser.SetInfo ' Now otherTelephoneNumber = 555-1212, 555-1213 ' Delete one of the values objUser.PutEx ADS_PROPERTY_DELETE, "otherTelephoneNumber", Array("555-1213") objUser.SetInfo ' Now otherTelephoneNumber = 555-1212 ' Change values objUser.PutEx ADS_PROPERTY_UPDATE, "otherTelephoneNumber", Array("555-1214") objUser.SetInfo ' Now otherTelephoneNumber = 555-1214 ' Clear all values objUser.PutEx ADS_PROPERTY_CLEAR, "otherTelephoneNumber", vbNullString objUser.SetInfo ' Now otherTelephoneNumber = <empty> See AlsoMSDN: IADs::Put, MSDN: IADs::PutEx, MSDN: IADs::SetInfo, and MSDN: ADS_PROPERTY_OPERATION_ENUM |