Searching the AD with scripts
Windows Server Forum Index Windows Server
Server discussion on Windows platform.
 
 FAQFAQ   MemberlistMemberlist     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Google
 
Web winserverhelp.com
Searching the AD with scripts

 
Post new topic   Reply to topic    Windows Server Forum Index -> Active Directory
Author Message
Liam Mac
Guest





Posted: Mon Jan 17, 2005 6:14 pm    Post subject: Searching the AD with scripts Reply with quote

Hi Folks,

Maybe someone can help me, I have written a VB scripts within Microsoft
Access to Search for Users based on CN name within Active Directory which
works fine. I have now populate all my user accounts "employeeID" field
within active directory with their staff ID. Now if I change the script to
search on employeeID within active directory instead of CN the search fails.
Any ideas on this would be a great help. below is my code the line comment
out is the line that works fine based on cn.

Cheers,
Liam
CODE:

Public Function FindUser(strUser)

strSearchBase = "LDAP://dc=wpa,dc=lyit,dc=local"
' strFilter = "(&(objectCategory=person) (cn=" & Soap Joe & "))" -- Work
fine
strFilter = "(&(objectCategory=person) (employeeID =6259))" - Does not
work
strAttribs = "ADsPath"
strScope = "subtree"
strCommandText = "<" & strSearchBase & ">;" & strFilter & ";" &
strAttribs & ";" & strScope

Set oConnection = CreateObject("ADODB.Connection")
Set oCommand = CreateObject("ADODB.Command")
oConnection.Provider = "ADsDSOObject"
oConnection.Open "Active Directory Provider"
Set oCommand.ActiveConnection = oConnection
oCommand.CommandText = strCommandText

Set oRecordset = oCommand.Execute(strCommandText)

UserRecord = ""
If Not oRecordset.EOF Then
FindUser = oRecordset.Fields.Item("ADsPath").Value
Else
FindUser = ""
End If

End Function
Back to top
Joe Richards [MVP]
Guest





Posted: Mon Jan 17, 2005 6:14 pm    Post subject: Re: Searching the AD with scripts Reply with quote

When you say it fails does it throw an error or does it not return anything?

The quick look I took one issue I see is

(employeeID =6259)

which should result in an internal query of <<UNKNOWN>>. It needs to be

(employeeID=6259)


quite honestly this

(cn=" & Soap Joe & ")

wouldn't work either. That should be a syntax error. Soap and Joe are vars in
this context and you can't put them together that way.


joe

--
Joe Richards Microsoft MVP Windows Server Directory Services
www.joeware.net


Liam Mac wrote:
Quote:
Hi Folks,

Maybe someone can help me, I have written a VB scripts within Microsoft
Access to Search for Users based on CN name within Active Directory which
works fine. I have now populate all my user accounts "employeeID" field
within active directory with their staff ID. Now if I change the script to
search on employeeID within active directory instead of CN the search fails.
Any ideas on this would be a great help. below is my code the line comment
out is the line that works fine based on cn.

Cheers,
Liam
CODE:

Public Function FindUser(strUser)

strSearchBase = "LDAP://dc=wpa,dc=lyit,dc=local"
' strFilter = "(&(objectCategory=person) (cn=" & Soap Joe & "))" -- Work
fine
strFilter = "(&(objectCategory=person) (employeeID =6259))" - Does not
work
strAttribs = "ADsPath"
strScope = "subtree"
strCommandText = "<" & strSearchBase & ">;" & strFilter & ";" &
strAttribs & ";" & strScope

Set oConnection = CreateObject("ADODB.Connection")
Set oCommand = CreateObject("ADODB.Command")
oConnection.Provider = "ADsDSOObject"
oConnection.Open "Active Directory Provider"
Set oCommand.ActiveConnection = oConnection
oCommand.CommandText = strCommandText

Set oRecordset = oCommand.Execute(strCommandText)

UserRecord = ""
If Not oRecordset.EOF Then
FindUser = oRecordset.Fields.Item("ADsPath").Value
Else
FindUser = ""
End If

End Function
Back to top
 
Post new topic   Reply to topic    Windows Server Forum Index -> Active Directory All times are GMT
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




New Topics Powered by phpBB