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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AD description output error

Status
Not open for further replies.

whoslinus

IS-IT--Management
Jul 2, 2009
11
DE



hi all was wondering why this code is not working. I am trying to get an output of the "description" col in AD . It is giving me a current record set does not support the data







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.CommandText = _
"Select Name, Location, description from 'LDAP://xx' " _
& "Where objectClass='computer'"
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst

Do Until objRecordSet.EOF


objRecordSet.Fields("description").Value = ""
arrDesc = objRecordSet.Fields("description").Value

If IsNull(arrDesc) Then
strDescription = ""
Else
For Each strLine In arrDesc
strDescription = strLine
Next
End If
Wscript.Echo "Computer Name: " & objRecordSet.Fields("Name").Value
Wscript.Echo "Location: " & objRecordSet.Fields("Location").Value
Wscript.Echo strName & ", " & strDescription
objRecordSet.MoveNext
Loop
 
[1] >objRecordSet.Fields("description").Value = ""
What is this line for? You have objRecordSet being read-only. Take the line out.

[2] >arrDesc = objRecordSet.Fields("description").Value
The description field is a string, not an array. If you want to keep the structure testing null, you can do it like this.
[tt]
arrDesc = objRecordSet.Fields("description").Value

If IsNull(arrDesc) Then
strDescription = ""
Else
[red]'[/red]For Each strLine In arrDesc
[red]'[/red]strDescription = strLine
[red]'[/red]Next
[blue]strDescription=arrDesc[/blue]
End If
[/tt]
 
Cheers tsujii
I am now getting type miss match on the description....
The program will throw out the pc name and location
but the errors on description. I am puzzeled, i tried using a str varibale to no effect.


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.CommandText = _
"Select Name, Location, description from 'LDAP://x, DC=net' " _
& "Where objectClass='computer'"
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst

Do Until objRecordSet.EOF

arrDesc = objRecordSet.Fields("description").Value

If IsNull(arrDesc) Then
strDescription = ""
Else
strDescription=arrDesc
End If




Wscript.Echo "Computer Name: " & objRecordSet.Fields("Name").Value
Wscript.Echo "Location: " & objRecordSet.Fields("Location").Value
Wscript.Echo strName & ", " & strDescription
objRecordSet.MoveNext
Loop
 
Change the conditional from objectClass to objectCategory.
[tt] where objectCategory='computer'[/tt]
 
still getting type miss match on Wscript.Echo strName & ", " & strDescription is it to do with the string name?
 
I don't see anywhere define strName. Why should it be there out of nowhere?
 
Same issue again today. i have tried removing the string name to no effect should the "If IsNull(arrDesc) Then"
outside the end of record set?
 
strDescription=arrDesc

wscript.echo is string to implicitly convert (by proxy arrDesc) to a string....is it really a string?
 
I don't see any reason for a type mismatch on that line. Are you sure it's on that line? Maybe you should post the entire script.
 
<no reason for a type mismatch on that line>....

logically this would occur if you try and get Wscript.Echo to implicitly convert 'something' to a string which doesnt like being converted......e.g....hmm, an array of some description, something which is 'NULL',,,some other random object which doesnt a 'oh if something tries to print me i better give some some lovely string'
 
whoslinus,,,,make an effort to explicitly convert it to a string if you want it in a string format/form

with recordset stuff in general you need to be careful

If Not IsNull(objRecordSet.Fields("Location").Value) Then '''echo or assign to a varaible you are going to treat as a string

...but seeing as you are doing an IsNull() on the strDescription bit already and according to AD that attribute is a unicode string so shouldnt be returning anything other than a string .....then see tsuji's post about strName

 
mrmovie,

Agreed, but I don't see how that could happen with the code posted. So, my guess is that there is something going on that we are not seeing.
 
its usually a funky party with some hot chicks :) have a good weekend
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top