English (UK)

Query Active Directory from VBScript and OLE DB connection

Const ADS_SCOPE_SUBTREE = 2

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

objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 

objCommand.CommandText = "SELECT SamAccountName FROM 'LDAP://dc=MyDomain,dc=it' WHERE givenName='MyUser'"
Set objRecordSet = objCommand.Execute

If objRecordset.RecordCount = 1 Then
 WScript.Echo "Found"
Else
 WScript.Echo "Not found"
End If
objRecordset.Close

 


© 2017 Bruno Tessaro. My life in the web. All right reserved.