Const OUTPUT_FILE = "out.txt"
Dim objConnection : Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOOBject"
objConnection.Open "Active Directory Provider"
Dim objCommand : Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
' Get the current Domain to use with the Search Base
'Dim objRootDSE : Set objRootDSE = GetObject("LDAP://RootDSE")
'Dim strDomainDN : strDomainDN = objRootDSE.Get("defaultNamingContext")
'Set objRootDSE = Nothing
' Run the search from here down
Dim strBase : strBase = ""
' The LDAP Filter to return computers who are in Domain Computers, but nothing else
Dim strFilter : strFilter = "(&(objectCategory=computer)(primaryGroupID=515)(!memberOf=*))"
' List all attributes required
Dim strAttributes : strAttributes = "distinguishedName,CN"
Dim strQuery : strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
objCommand.CommandText = strQuery
objCommand.Properties("Page Size") = 999999
objCommand.Properties("Timeout") = 300
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute
' Set up a file to write the results to
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objFile : Set objFile = objFSO.OpenTextFile(OUTPUT_FILE, 2, True, 0)
Do Until objRecordSet.EOF
objFile.WriteLine objRecordSet.Fields("CN").Value
objRecordSet.MoveNext
Loop
Set objFile = Nothing
Set objFSO = Nothing
Set objRecordSet = Nothing
Set objCommand = Nothing
objConnection.Close
Set objConnection = Nothing
|