Liam Mac
Guest
|
Posted:
Mon Jan 17, 2005 6:14 pm Post subject:
Searching the AD with scripts |
|
|
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 |
|
Joe Richards [MVP]
Guest
|
Posted:
Mon Jan 17, 2005 6:14 pm Post subject:
Re: Searching the AD with scripts |
|
|
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
|
|
|