Platform SDK: Active Directory, ADSI, and Directory Services

Get Method

Individual properties can be retrieved from the directory using the IADs::Get method.

The following example retrieves a property by name from an object using IADs::Get.

Dim MyUser as IADs
Dim MyCommonName as String
 
' Bind to a specific user object.
set MyUser = GetObject("LDAP://CN=JeffSmith,OU=MyOrgUnit")
 
' Get property
MyCommonName = MyUser.Get("CN")

From Automation languages, you can use the property name directly using the dot notation. For example, you can write MyObject.Name or MyObject.Class to access the Name and Class properties defined on IADs.

The following example retrieves a property directly from an Active Directory™ object using the standard IADs interface and the Name property it supports.

Dim MyUser as IADs
Dim MyName as String
 
' Bind to a specific user object.
Set MyUser = GetObject("LDAP://MyMachine/CN=JeffSmith,DC=Fabrikam,DC=COM")
 
' Get property
MyName = MyUser.Name

You can also use the name of the schema object that describes the property. Pass the name of the property as it is defined in the schema as the first parameter.

Dim MyUser as IADs
Dim MyName as String
 
' Bind to a specific user object.
set MyUser = GetObject("LDAP://CN=JeffSmith,OU=MyOrgUnit")
 
' Get property
MyName = MyUser.Get("distinguishedName")

From languages that do not use Automation, you can also use the IADs::Get method and its related methods as described previously. In addition, you can use the get_propertyname methods supported on all ADSI interfaces.

IADs       *pUser; 
BSTR       bstrName;
HRESULT    hr;
 
// Bind to user object
hr = ADsGetObject(L"WinNT://MyDomain/Users/Jeff", IID_IADs, (void**)&pUser);
 
// Get property
if (SUCCEEDED(hr)) {
    hr = pUser->get_Name(&bstrName);
 
    if (SUCCEEDED(hr)) {
        printf("%S\n", bstrName);
    }
 
    SysFreeString(bstrName)
}