Discussion Locked

ADSI Scripting

0 helpful
15 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I have a simple problem with ADSI scripting, and that is how do you clear an attribute?

I have tried many things, including:
* Using spaces (can cause strange problems)
* NULL (program error)
* null string "" (causes error)

Any ideas?

15 replies

by stillatit

As I understand it, you don't. Typically, you create an (instance of an) object, fill in the attributes, do the action on the object, then release the object. If you want to do another one, you get a new object. In this way the attributes you put inone do not carry over to the next.

If you MUST "clear" an attribute, you clear it by putting an acceptable value into it. If you are creating a user, for example, you cannot "clear" the last name, because a null string (nor a space) is not a valid content for this attribute. "Unknown" (a string) would be.

Good luck.

by mcorr

I MUST clear an attribute, and replace it with nothing. The problem is that I am trying to clear the User Profile Path, and instead use the Terminal Services Profile Path. The problem is that any character in the User Profile Path causes problems during login.

by mcorr

Also I don't want to recreate all 8000 user objects in our tree, so creating a new one and leaving it blank will not work.

Thanks, Chris

by mcorr

Point value changed by question poster to 2000 points! Last chance! Blah Blah Blah :)

by maxwell edison

Microsoft Knowledge Base Article - Q260251: This step-by-step article describes how to use Active Directory Services Interface (ADSI) to create, change, and remove Lightweight Directory Access Protocol (LDAP) directory attribute values.

http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q260251&

An excerpt from the article: “...if an attribute is modified to have no value (or values), the entire attribute is removed. At times you may want to set an attribute to null. While thisconcept does not exist in directories that support LDAP, you can accomplish this by removing the attribute entirely and specifying that the property is to be cleared. This behavior is consistent with the LDAP specification. Queries of the attribute value must expect the absence of the attribute itself and handle any error that may arise.”

Some attributes, however, are mandatory, and cannot be cleared. The system sets these mandatory attributes, except for one, sAMAccountName, which specifies the name that represents the user to NT clients and servers that are lower in the Win2K hierarchy. You must set the sAMAccountName attribute before you call IADs::SetInfo. This article discusses those as well as other methods for manipulating account information using ADSI.

http://www.winscriptingsolutions.com/Articles/Index.cfm?ArticleID=5456

The preceding is one chapter from an excellent series of 12 articles on ADSI. All 12 articles may be accessed from the following link:

http://www.iisfaq.com/default.asp?View=A343&Print=1

An excerpt from Chapter 6 of the article: “The next two sections attempt to enable and unlock the user account, respectively. However, the script doesn't quit if an attempt fails. The Err::Clear method, which works only if you enable On Error Resume Next, clears the error object so that you can detect the next error.”

REMOVE SPACES from the pasted URLs.

by borco

I do not remember the Microsoft Q about how to set, reset and clear attribute with ADSI scripting, but what I remember is:
Use PutEx instead of Put and do not forget SetInfo e.g.

SomeObject.PutEx ADS_PROPERTY_CLEAR, "SomeAttrib", 0
SomeObject.SetInfo

Hope that help

by jack republic

Hi try this exemple:
Const ADS_PROPERTY_CLEAR = 1
Set objUser = GetObject _
("LDAP://cn=myerken,ou=management,dc=fabrikam,dc=com")

objUser.PutEx ADS_PROPERTY_CLEAR, "profilePath", 0
objUser.PutEx ADS_PROPERTY_CLEAR, "c", 0

objUser.SetInfo

good luck

This discussion is closed to new replies.