Query Active Directory from VBScript and OLE DB connection

Print
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

 

This website uses cookies to ensure you get the best experience on our website.