|
|
Table of Contents |
|
Querying User InformationReading user information (or group information, for that matter) requires the use of the Get method, as well as the name of the attribute you want to read. In the previous chapter, I showed you how to use the AD Schema console to browse a class for its available attributes; you can use the same technique on the user and group classes to see what attributes they support. To query information, simply connect to the object in question and use Get to retrieve the attribute values that you need.
Dim oUser
Set oUser = GetObject("LDAP://cn=DonJ,ou=MIS,dc=domain,dc=com")
WScript.Echo oUser.Get("name")
WScript.Echo oUser.Get("description")
WScript.Echo oUser.Get("sAMAccountName")
That's easy enough. Using the WinNT provider, you can directly access many attributes that are exposed as regular properties.
Dim oUser
Set oUser = GetObject("WinNT://DOMAIN/DonJ")
WScript.Echo oUser.Name
WScript.Echo oUser.Description
One thing to be careful of with the WinNT provider is that it grabs the first object it finds matching your query. For example, if I have a user and a group named DonJ, the preceding example might bind to the user or the group. You can force the object type by specifying it.
Dim oUser
Set oUser = GetObject("WinNT://DOMAIN/DonJ,user")
WScript.Echo oUser.Name
WScript.Echo oUser.Description
You can also use Get with the WinNT provider, making its syntax parallel to the LDAP provider. Keep in mind that user objects have a number of multivalued attributes, as I mentioned in Chapter 14. Reading those requires a slightly different technique.
Dim oUser
Set oUser = GetObject("LDAP://cn=DonJ,ou=MIS,dc=domain,dc=com")
Dim sURL
For Each sURL in objUser.GetEX("url")
WScript.Echo sURL
Next
In this case, I'm working with the "url" attribute of a user object, which can actually contain multiple URLs. The GetEx method retrieves them all into a collection, which I iterate through by using a For Each…Next collection. |
|
|
Table of Contents |
|