Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Searching Active Directory

Status
Not open for further replies.

rbri

Programmer
Jun 27, 2002
84
0
0
US
Hello everyone

I am having a strange thing happen and I wonder if anyone can help me see where I am going wrong. I wrote a vbscript/hta to search AD and display the results in a text box. The whole program works good until I was asked to add the field containing our mail stop. It took me awhile to figure out the name of the field but, I finally did the field name is "destinationIndicator". When I try to get that value however it always comes back empty. If I try to display the value in a msgBox the scripts errors saying there is a Null value, and if I use the function VarType that says its a Null value. If I use the command line, command csvde -f export.cvs -r "(&(objectClass=user)(sn=Thomas))" it generates a file with all my information and in the field named "destinationIndicator" is my mail stop, could someone tell me what I am missing. Below is a portion of my code that is getting the information from AD.
*****************************************************
' Determine DNS domain name.
Set oRootDSE = GetObject("GC://RootDSE")
sDNSDomain = oRootDSE.Get("defaultNamingContext")
sDNSDomain = Right(sDNSDomain, 20)
strLName = "(SN=" & strMySearch & ")"

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

strBase = "<GC://" & sDNSDomain & ">"
strFilter = "(&(objectCategory=person)(objectClass=user)" & strLName & ")"
strAttributes = "cn,mail,telephoneNumber,company,streetAddress,l,co,SAMAccountName,postalcode,destinationIndicator"
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
objCommand.CommandText = strQuery
objCommand.Properties("Page Size") = 100
objCommand.Properties("Timeout") = 30
objCommand.Properties("Cache Results") = False
objCommand.Properties("Sort On") = "SN"
Set objRecordSet = objCommand.Execute

If objRecordSet.EOF Then
MsgBox "No user found by this name: " & strMySearch
End If
*****************************************************
This code is working it just doesn't seem to find the value stored in the "destinationIndicator". If you want more or the rest of the script let me know and thanks for any help I can get I have run out of ideas.

Thanks Randy
 
The destinationIndicator is of data type IA5String (documented in adsi schema). It is some subset of octet strings. vbs variable can take on this type of data, but to manipulate and display it, it needs some further work. Hopefully this might get it display.
[tt]
dim osdi,sdi
'osdi the data retrieved from the resultset
'you can display ubound(osdi) by wscript.echo for checking
osdi=ors.fields("destinationIndicator").value
sdi=""
for i=0 to ubound(osdi)
sdi=sdi & chr("&h" & right("00" & hex(ascb(midb(osdi,i+1,1))),2))
next
'sdi here is printable string and can be display by wscript.echo for instance.
[/tt]
 
Hello tsuji

I get an error on the line containing the "Ubound' function it says "Type mismatch 'ubound'" I think the ubound command is wanting to see an array.

Thanks
 
destinationIndicator is optional attribute. There is no guarantee that every record in the resultset has a non-null value. Impose a control on testing whether it is null.
[tt]
if not isnull(ors.fields("destinationIndicator").value) then
'...etc etc
end if
[/tt]
Or you can setup the filter by including (destinationIndication=*), or something to that effect.
 
It still doesn't work it almost seems that the first character/field that is in the AD field distinationIndicator is a Null value and it never drops into the "if" loop because I get nothing. If I try the "=*" at the end I get a script error "unspecified error
 
Make sure my ors means your objRecordSet.
 
For some reason it never gets inside the loop it must think all the values are null. Here is what I was testing.

if not isnull(objRecordSet.fields ("destinationIndicator").value) then

MsgBox "Inside loop"
end if

Thanks
 
So you mean the rest are fine except that attribute? (just to be clear!)
 
That is correct I get data from all the other values requested the destinationIndicator is the only one that comes back empty.
 
[1]
>[self]Or you can setup the filter by including (destinationIndication=*), or something to that effect.
>>If I try the "=*" at the end I get a script error "unspecified error"
I meant, apart from an obvious typo, (destinationIndicator=*) as added to the filter (&(...)(...)(destinationIndicator=*)).... Of course, I did not mean to add =* to the attribute to retieve part.

[2] Though it is of certainty that destinationIndicator will be replicated, hence a search on GC:// should be viable, I think one further detail might help. Try to restrict the object to organizationalPerson. I thank that class object will expose the attribute in question.
[tt] strFilter = "(&(objectCategory=organizationalPerson)(objectClass=user)" & strLName & ")"[/tt]
 
Hello tsuji

I tried both of your suggestions and neither of them worked suggestion (1) returns an error that no person was found by that name that is my error message but, it goes there if the search was unsucessful, and sugesstion (2) returns the same result as my code where the value is empty.

Thanks Randy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top