Submitted By: Stu Charlton

Lists all the computer accounts in a specified OU.

Visual Basic
Edit|Remove
Const ADS_SCOPE_SUBTREE = 2

'set ADLOOKUP value to your ORG and OU
ADLOOKUP = "Select Name, Location from 'LDAP://OU=AA, DC=COMPANY, DC=com' "

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"

Set objCOmmand.ActiveConnection = objConnection
objCommand.CommandText = _
    ADLOOKUP _
        & "Where objectClass='computer'"
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst

Do Until objRecordSet.EOF
    Wscript.Echo "Computer Name: " & objRecordSet.Fields("Name").Value
    Wscript.Echo "Location: " & objRecordSet.Fields("Location").Value
    objRecordSet.MoveNext
Loop