To the scripting
gurus:
This one is kind of
driving me nuts so any clarification on why this happens would be greatly
appreciated.
I recently created a
script for one of our agency OU admins that queried the AD for their
workstations and returned name, distinguished name, description, and some
operating system details. The guts of the script are shown
below. What I found is that "description" is what I think is a
multi-variate field and the line "strDescrip =
objRecordSet.Fields("description").Value" barks at me. WSH returns "Type
mismatch code 800A000D" error.
I got around this by
shimming in a call back to the original object and adding in a return
of ADSpath to the ADO query. I set the description string via
a GetObject call and I don't get any errors - "strDescrip =
GetObject(strADSPath).description".
My questions to the
scripting gurus in the group are:
1. When doing an ADO
query, how to you handle things that return arrays or multi-variate
attributes?
2. Is there
something within the "objRecordSet.Fields..." bit that you can turn on to force
a single value or pick a value from an returned multi-variate or
array??
3. Why does an
return from an ADO query be any different than a "GetObject" return?
Or in other words, why should description bark in an ADO query but be fine in a
normal GetObject?
Thanks,
Stuart
Fuller
Sometimes cheesy
scripting person
State of
Montana
===============ADO
query script ==============
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, distinguishedName, description, operatingSystem, operatingSystemServicePack, operatingSystemVersion from 'LDAP://ou=SomeOU,dc=ChildDomain,dc=RootDomain,dc=Root' " _
& "where objectClass='computer'"
objCommand.Properties("Page Size") = 2000
objCommand.Properties("Timeout") = 60
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
strName = objRecordSet.Fields("Name").Value
strDescrip = objRecordSet.Fields("description").Value
strOS = objRecordSet.Fields("operatingSystem").Value
strOSV = objRecordSet.Fields("operatingSystemVersion").Value
strOSSP = objRecordSet.Fields("operatingSystemServicePack").Value
strLocation = objRecordSet.Fields("distinguishedName").Value
fileTxt.WriteLine(strName & "," & strDescrip & "," & strOS & "," & strOSV & "," & strOSSP & "," & strLocation)
objRecordSet.MoveNext
Loop
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, distinguishedName, description, operatingSystem, operatingSystemServicePack, operatingSystemVersion from 'LDAP://ou=SomeOU,dc=ChildDomain,dc=RootDomain,dc=Root' " _
& "where objectClass='computer'"
objCommand.Properties("Page Size") = 2000
objCommand.Properties("Timeout") = 60
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
strName = objRecordSet.Fields("Name").Value
strDescrip = objRecordSet.Fields("description").Value
strOS = objRecordSet.Fields("operatingSystem").Value
strOSV = objRecordSet.Fields("operatingSystemVersion").Value
strOSSP = objRecordSet.Fields("operatingSystemServicePack").Value
strLocation = objRecordSet.Fields("distinguishedName").Value
fileTxt.WriteLine(strName & "," & strDescrip & "," & strOS & "," & strOSV & "," & strOSSP & "," & strLocation)
objRecordSet.MoveNext
Loop
wscript.echo
"DONE"
==========Bad fix to
make it work=============
Do Until
objRecordSet.EOF
strName = objRecordSet.Fields("Name").Value
==> strADSPath = objRecordSet.Fields("ADSPath").Value
==>' Go get multi-valued description attribute from object using ADSpath
==> strDescrip = GetObject(strADSPath).description
strOS = objRecordSet.Fields("operatingSystem").Value
strOSV = objRecordSet.Fields("operatingSystemVersion").Value
strOSSP = objRecordSet.Fields("operatingSystemServicePack").Value
strLocation = objRecordSet.Fields("distinguishedName").Value
fileTxt.WriteLine(strName & "," & strDescrip & "," & strOS & "," & strOSV & "," & strOSSP & "," & strLocation)
objRecordSet.MoveNext
Loop
strName = objRecordSet.Fields("Name").Value
==> strADSPath = objRecordSet.Fields("ADSPath").Value
==>' Go get multi-valued description attribute from object using ADSpath
==> strDescrip = GetObject(strADSPath).description
strOS = objRecordSet.Fields("operatingSystem").Value
strOSV = objRecordSet.Fields("operatingSystemVersion").Value
strOSSP = objRecordSet.Fields("operatingSystemServicePack").Value
strLocation = objRecordSet.Fields("distinguishedName").Value
fileTxt.WriteLine(strName & "," & strDescrip & "," & strOS & "," & strOSV & "," & strOSSP & "," & strLocation)
objRecordSet.MoveNext
Loop
