Platform SDK: Active Directory, ADSI, and Directory Services

Domains

The ADSI Domain object's available properties vary depending on what namespace the object resides in. A script can determine what properties a given domain supports by looking at the Domain object's schema class object. A schema class object contains definitions of all the methods and properties that are supported by an object under a particular namespace provider. The ADsPath to an object's schema class object is stored in the Schema property. The Schema property is available on any ADSI object, not just domains.

A schema class object must be bound to retrieve useful information from it. The following lines of code show how to bind to the schema class object for a particular domain:

Set myDomain = GetObject("WinNT://mydomain")
Set mySchemaClass = GetObject(myDomain.Schema)

Once the schema class object has been bound, its properties offer a wealth of information about an object's supported properties, as well as its relation to other objects within its namespace. The schema class object has the following useful properties.

Property Description
Container A Boolean value, True if the object is a container, False if not.
Containment If the object is a container, the Containment property holds a list of all the types of ADSI objects this particular object can contain.
MandatoryProperties An array of all the properties that must be set for this object to be written to storage.
OptionalProperties An array of this object's optional properties.

The following script displays the properties available in a given WinNT domain:

Dim myDomain
Dim mySchemaClass
Dim member

Set myDomain = GetObject("WinNT://MYDOMAIN")
Set mySchemaClass = GetObject(myDomain.Schema)

WScript.Echo "Properties for the " & myDomain.Name & " object"
WScript.Echo

If mySchemaClass.Container Then
    WScript.Echo myDomain.Name & " may contain the following objects:"
    For Each member In mySchemaClass.Containment
        WScript.Echo "    " & member
    Next
Else
    WScript.Echo myDomain.Name & " is not a container."
End If
WScript.Echo

WScript.Echo "Mandatory properties:"
For Each member In mySchemaClass.MandatoryProperties
    WScript.Echo "    " & member
Next
WScript.Echo

WScript.Echo "Optional properties:"
For Each member In mySchemaClass.OptionalProperties
    WScript.Echo "    " & member
Next

This script will produce output similar to the following:

Properties for the MYDOMAIN object

MYDOMAIN may contain the following objects:
    Computer
    User
    Group

Mandatory properties:

Optional properties:
    MinPasswordLength
    MinPasswordAge
    MaxPasswordAge
    MaxBadPasswordsAllowed
    PasswordHistoryLength
    AutoUnlockInterval
    LockoutObservationInterval

Note that this script may be used to retrieve the properties of any ADSI object, not just domains. Simply replace the path in the first GetObject call with the path to the object whose properties you are interested in.