'==========================================================================
'
' VBScript:  AUTHOR: Ed Wilson , MS,  7/1/2006
'
' NAME: <filtercomputers.vbs>
'ver.1.2 Renamed variables, cleaned up code.
' COMMENT: Key concepts are listed below:
'1.Uses an ADO query to retrieve list of computers from AD.
'2.Filters on ObjectCategory = computer. user, printqueue, 
'3.group, organizationalUnit are other possible values for this
'4.attribute. Prints out objRecordSet("Name") attribute. Note, this 
'5.is same as:  objRecordSet.fields ("name")
'==========================================================================
Option Explicit
On Error Resume Next
dim strQuery			'The LDAP syntax query into AD
dim objConnection	'ADODB object
dim objCommand		'Command object
dim objRecordSet	'Recordset returned by executing the strQuery

strQuery = "<LDAP://dc=nwtraders,dc=msft>;" & _
		"(objectCategory=computer);" &_ 
       "name,distinguishedName;subtree"

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Open "Provider=ADsDSOObject;"
objCommand.ActiveConnection = objConnection
objCommand.CommandText = strQuery
Set objRecordSet = objCommand.Execute

Do until objRecordSet.EOF
	WScript.echo objRecordSet("name"), objRecordSet("distinguishedName")
objrecordset.MoveNext
loop

objConnection.Close
