Experts Exchange connects you with the people and services you need so you can get back to work.
Const ADS_SCOPE_SUBTREE = 2
Const adUseClient = 3
OU = "YOUR OU HERE" 'Enter your OU here
strDNC = "DC=YOUR DOMAIN,DC=HERE" ' Enter your AD root here
FindWhat = "user" ' Change to either user or computer to find either users or computer in the AD
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
Set objStdOut = WScript.StdOut
'=================================================Main Routine Start ===============================================
Call QueryTheAD 'Get List from the AD
'=================================================Main Routine End ===============================================
objCommand.CommandText = "Select Name, Location from 'LDAP://" & strDNC & "' " & "Where objectClass='"& FindWhat & "'"
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.Properties("Sort on") = "Name"
Set objRecordSet = objCommand.Execute
Do Until objRecordSet.EOF
MachineCount = MachineCount + 1
strComputer = objRecordSet.Fields("Name").Value
Open in new window
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
Please enter a first name
Please enter a last name
Must be at least 4 characters long.
Join and Comment
Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.