On Error Resume Next
Const ADS_SCOPE_SUBTREE = 2
Set objOU = GetObject(“LDAP://OU=test,DC=test,DC=com”)
Set objConnection = CreateObject(“ADODB.Connection”)
objConnection.Provider = “ADsDSOObject”
objConnection.Open “Active Directory Provider”
Set objCommand = CreateObject(“ADODB.Command”)
Set objCommand.ActiveConnection = objConnection
objCommand.Properties(“Page Size”) = 1000
objCommand.Properties(“Searchscope”) = ADS_SCOPE_SUBTREE
objCommand.CommandText = “SELECT ADsPath FROM ‘LDAP://dc=test,dc=com’ WHERE NAME=’jojo'”
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
strADsPath = objRecordSet.Fields(“ADsPath”).Value
objOU.MoveHere strADsPath,vbNullString
objRecordSet.MoveNext
Loop