In this section, you will modify the \My Documents\MicrosoftPress\VBScriptSBS\ch13 \OneStepFurther\FilterMoreComputers.vbs script to control the way it executes while querying Active Directory.
1. | Open the FilterMoreComputers.vbs script in Notepad or your favorite script editor and save the script as YourNameOSFcontrolScriptQuery.vbs.
|
2. | On the line following the objCommand.CommandText = qQuery statement, add an objCommand property statement that will change the default asynchronous behavior from false to true. The amended script will look like the following:
Option Explicit
'On Error Resume Next
Dim qQuery
Dim objConnection
Dim objCommand
Dim objRecordSet
qQuery = "<LDAP://dc=nwtraders,dc=msft>;" & _
"(objectCategory=computer)" & _
";distinguishedName,name;subtree"
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Open "Provider=ADsDSOObject;"
objCommand.ActiveConnection = objConnection
objCommand.CommandText = qQuery
objCommand.properties("Asynchronous")=True
Set objRecordSet = objCommand.Execute
While Not objRecordSet.EOF
WScript.Echo objRecordSet.Fields("name")
WScript.Echo objRecordSet.Fields("distinguishedName")
objRecordSet.MoveNext
Wend
objConnection.Close
|
3. | Save the script.
|
4. | Open a command prompt and run the script in CScript. You should see output coming from the script, but you will probably NOT notice any difference.
|
5. | Turn off the caching of results by setting Cache Results to false. Do this under the objCommand.properties("Asynchronous") = True line you added in step 2. Your code for this command will look like the following:
objCommand.properties("cache results") = False
|
6. | Save and run the script. Again you probably will not see any difference in the output.
|
7. | Set a page size of 1 to tell Active Directory to return one object at a time. This line can go below the cache results setting specified in line 6. Your code will look like the following:
objCommand.properties("Page Size") = 1
|
8. | Save and run the script.
|
9. | Change the page size to 10 and set a size limit of 100 to limit the number of objects returned. The two lines of code will look like the following:
objCommand.properties("Page Size") = 10
objCommand.properties("Size limit") = 100
|
10. | Set a query time limit that will limit how long the server is allowed to search for results. You will use the Time Limit property, as shown in the following code. Place this code below the size limit line.
objCommand.Properties("Time Limit") = 2
|
11. | Save and run the script.
|
12. | Set a timeout value that will limit how long the client machine waits for results from the server. This value should be smaller than the time limit value.
objCommand.Properties("Timeout") = 1
|
13. | Save and run the script.
|
14. | Close your work.
|
To | Do This |
---|
Make an ADO connection into Active Directory | Use the ADsDSOObject provider with ADO to talk to Active Directory |
Modify an Active Directory query | Modify the search filter portion of the LDAP syntax query |
Tell ADO search to cache results on the client side of the connection | Use the Cache results property |
Directly query a Global Catalog server | Use GC:// in your connection moniker, instead of using LDAP:// |
Directly query a specific server in Active Directory | Use LDAP:// followed by the specific server name in your connection moniker, followed by a trailing / |
Use ADO to query an Access database | Use the Microsoft.Jet.OLEDB.4.0 provider and specify the name of the database as the data source |
Use ADO to query an Excel spreadsheet | Use the Microsoft.Jet.OLEDB.4.0 provider, specify Excel 8.0 as extended properties, and reference the spreadsheet by sheet name in square brackets with a trailing $ |
Query multiple attributes in an LDAP syntax query | Use a set of parentheses to surround each of the attributes, and place an ampersand at the beginning inside parenthesis to glue the two sets of attributes together |