NT
Sat Jul 21 13:40:01 CDT 2007
Thanks for the quick response Richard,
Please find most of my code below. Looks a bit untidy.
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
Myarray = Split(strLine, ",")
wscript.echo strLine
Array1 = Myarray(0)
If instr(Array1, SearchString) Then
StrResult = Mid(Array1,13)
'wscript.echo StrResult
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOOBject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
Set objRootDSE = GetObject("LDAP://RootDSE")
'Get domain
strDNSDomain = objRootDSE.Get("defaultNamingContext")
strBase = "<LDAP://" & strDNSDomain & ">"
'Define the filter elements
strFilter = "(&(objectCategory=person)(objectClass=user)(sAMAccountName=" &
StrResult & "))"
'List all attributes you will require
strAttributes =
"distinguishedName,sAMAccountName,givenName,sn,userPrincipalName"
'compose query
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
objCommand.CommandText = strQuery
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Timeout") = 300
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute
objFileW.WriteLine StrResult
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
strDN = objRecordSet.Fields("distinguishedName")
strGN = objRecordSet.Fields("givenName")
strsn = objRecordSet.Fields("sn")
strSA = objRecordSet.Fields("sAMAccountName")
strUN = objRecordSet.Fields("userPrincipalName")
'Wscript.Echo """" & strDN & """;""" & strSA & """;""" & strUN &
""";""" & strGN & """;""" & StrResult & """"
objFileW.WriteLine """" & strDN & """;""" & strSA & """;""" & strUN &
""";""" & strGN & """;""" & StrResult & """"
objRecordSet.MoveNext
'objFileW.WriteLine StrResult
Loop
'objFileW.WriteLine StrLine
End if
loop
' Clean up.
objFile.Close
objFilew.Close
objConnection.Close
Set objConnection = Nothing
Set objCommand = Nothing
Set objRootDSE = Nothing
Set objRecordSet = Nothing
"Richard Mueller [MVP]" wrote:
> NT wrote:
>
> > I have a spreadsheet where I want to search against the AD to verify if
> > users exist in the AD.
> >
> > I have used the "set objRecordSet = obcommand.Execute" but that only
> > return
> > all of the users it could find from my search string but it does not
> > return
> > the failed search users.
> > Can I use objcommand.properties("Cache Results") = True and list the
> > results
> > that way?
>
> ADO will return one record for each object in AD matching your search query.
> "Cache Results" will not affect this. Are you searching for each name one at
> a time with a query similar to below?
>
> "(sAMAccountName=" & strNTName & ")"
>
> Or are you searching for all names at once similar to below?
>
> "(|(sAMAccountName=" & strNTName1 & ")(sAMAccountName=" & strNTName2 & "))"
>
> Also, what names (or other search criteria) are you using? Are you using
> sAMAccountNames (also called NT names or "pre-Windows 2000 logon names"),
> Distinguished Names, First and Last names (attributes sn and givenName), or
> something else?
>
> If you search for one name at a time, either you find the object or you do
> not. If you search for all names at once using the OR operator "|", you get
> one record for each object found. If the names are NT names
> (sAMAccountName), instead of using ADO you can use the NameTranslate object
> to convert the NT name to the Distinguished Name. An error is raised that
> you can trap if no object exists with the specified name. This is more
> efficient than searching AD repeatedly.
>
> May need to see some of your code to help.
>
> --
> Richard Mueller
> Microsoft MVP Scripting and ADSI
> Hilltop Lab -
http://www.rlmueller.net
> --
>
>
>