I'm trying to iterate through the names of all the computers in an OU in ActiveDirectory. My code is bombing at "Set objADOList = objADOCmd.Execute". The error is RTE 3709: The connection cannot be used to perform this operation. It is either closed or invalid in this context.
I've found dozens of examples to do this, and all of them look the same. However, there are two factors that might be impeding me. First, they've all used implicitly-created variables, which I do not wish to do. Second, they all use generic objects (variable type "Object" rather than objects from the ADO reference (variable type ADODB.whatever). So, I'm forging ahead on my own trying to determine which variable types to use.
Can anybody see what I'm doing wrong?
Sub ScanComputersOU() Dim objADOObject As ADODB.Connection Dim objADOCmd As ADODB.Command Dim objADOList As ADODB.Recordset Dim objADORecord As ADODB.Record Set objADOObject = CreateObject("ADODB.Connection") Set objADOCmd = CreateObject("ADODB.Command") objADOCmd.CommandText = _"<LDAP://mn-min-dc1.domainname.com/ou=Computers,dc=domainname,dc=com>;objectClass=computerName;ADSPath;subtree" Set objADOList = objADOCmd.Execute For Each objADORecord In objADOList Next Set objADORecord = Nothing Set objADOList = Nothing Set objADOCmd = Nothing Set objADOObject = Nothing End Sub ' ScanComputersOU