Hello,

I'm modifying a web page to display all active directory computer
names along with their descriptions, os versions and service packs.

All of the values return correctly except "description". That value
returns a "type mismatch" error on the page.

If I comment out this line:
response.write "<br>Desc : "&description
Then it works fine.

It seems that "description" is multi-value and must be handled
differently then "name" and "operatingSystemVersion".

How would I modify the code accordingly?

Thanks

-----

<%Option Explicit%>
<HTML>
<BODY>
<%

Const ADS_SCOPE_SUBTREE = 2
dim objconnection
dim objcommand
dim objRecordSet
dim name
dim description
dim operatingSystemVersion
dim operatingSystemServicePack

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, description, operatingSystemVersion,
operatingSystemServicePack FROM 'LDAP://DC=domain,DC=com'" _
& " where objectClass='computer'"
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Timeout") = 30
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst

Do While not objRecordSet.EOF

name=objRecordSet.Fields("Name").value
description=objRecordSet.Fields("description").value

operatingSystemVersion=objRecordSet.Fields("operatingSystemVersion").value

operatingSystemServicePack=objRecordSet.Fields("operatingSystemServicePack").value

response.write "<br>Name : "&name
response.write "<br>Desc : "&description
response.write "<br>OS : "&operatingSystemVersion
response.write "<br>SP : "&operatingSystemServicePack
response.write "<br>"

objRecordSet.MoveNext
Loop

'response.write objRecordSet.EOF
%>
</BODY>
</HTML>

Re: Enumerate AD Computer Description by Richard

Richard
Thu May 26 20:34:33 CDT 2005

Hi,

The description attribute is strange. Most times you treat it as a
single-valued string, but the schema defines it as multi-valued. ADO
returns an array, even though there is only one element. I have used code
similar to below to retrieve the value using ADO:

Dim arrDescr
Do Until objRecordset.EOF
arrDescr = objRecordset.Fields("description").Value
If Not IsNull(arrDescr) Then
For Each strLine In arrDescr
Wscript.Echo strLine
Next
End If
objRecordset.MoveNext
Loop

The value is retrieved as an array, but you must make sure it is not null
before looping through the array. If it is Null, you can assign or display
an empty string.

--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab web site - http://www.rlmueller.net
--
"Name" <email@somewhere.com> wrote in message
news:m4sc91p1e9vga0e07sa2c5a2s307k8kqc4@4ax.com...
> Hello,
>
> I'm modifying a web page to display all active directory computer
> names along with their descriptions, os versions and service packs.
>
> All of the values return correctly except "description". That value
> returns a "type mismatch" error on the page.
>
> If I comment out this line:
> response.write "<br>Desc : "&description
> Then it works fine.
>
> It seems that "description" is multi-value and must be handled
> differently then "name" and "operatingSystemVersion".
>
> How would I modify the code accordingly?
>
> Thanks
>
> -----
>
> <%Option Explicit%>
> <HTML>
> <BODY>
> <%
>
> Const ADS_SCOPE_SUBTREE = 2
> dim objconnection
> dim objcommand
> dim objRecordSet
> dim name
> dim description
> dim operatingSystemVersion
> dim operatingSystemServicePack
>
> 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, description, operatingSystemVersion,
> operatingSystemServicePack FROM 'LDAP://DC=domain,DC=com'" _
> & " where objectClass='computer'"
> objCommand.Properties("Page Size") = 1000
> objCommand.Properties("Timeout") = 30
> objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
> objCommand.Properties("Cache Results") = False
> Set objRecordSet = objCommand.Execute
> objRecordSet.MoveFirst
>
> Do While not objRecordSet.EOF
>
> name=objRecordSet.Fields("Name").value
> description=objRecordSet.Fields("description").value
>
> operatingSystemVersion=objRecordSet.Fields("operatingSystemVersion").value
>
>
operatingSystemServicePack=objRecordSet.Fields("operatingSystemServicePack")
.value
>
> response.write "<br>Name : "&name
> response.write "<br>Desc : "&description
> response.write "<br>OS : "&operatingSystemVersion
> response.write "<br>SP : "&operatingSystemServicePack
> response.write "<br>"
>
> objRecordSet.MoveNext
> Loop
>
> 'response.write objRecordSet.EOF
> %>
> </BODY>
> </HTML>
>



Re: Enumerate AD Computer Description by Name

Name
Mon May 30 22:19:39 CDT 2005

That did it, thank-you Richard!

On Thu, 26 May 2005 20:34:33 -0500, "Richard Mueller [MVP]"
<rlmueller-NOSPAM@ameritech.NOSPAM.net> wrote:

>Hi,
>
>The description attribute is strange. Most times you treat it as a
>single-valued string, but the schema defines it as multi-valued. ADO
>returns an array, even though there is only one element. I have used code
>similar to below to retrieve the value using ADO:
>
>Dim arrDescr
>Do Until objRecordset.EOF
> arrDescr = objRecordset.Fields("description").Value
> If Not IsNull(arrDescr) Then
> For Each strLine In arrDescr
> Wscript.Echo strLine
> Next
> End If
> objRecordset.MoveNext
>Loop
>
>The value is retrieved as an array, but you must make sure it is not null
>before looping through the array. If it is Null, you can assign or display
>an empty string.
>
>--
>Richard
>Microsoft MVP Scripting and ADSI
>Hilltop Lab web site - http://www.rlmueller.net