Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Filter existing recordset for objectClass

Reply
 
Old 02-18-2009   #1 (permalink)
James Whitlow


 
 

Filter existing recordset for objectClass

Does anyone know if it is possible to filter an existing Active Directory
recordset using the 'objectClass' attribute?

I know I can do this:

oRS.Open "<LDAP://" & sDomainDN & ">;(&(objectClass=contact)" _
& "(displayName=Doe, John));cn,objectClass"

But can I do this?:

oRS.Open "<LDAP://" & sDomainDN & ">;(displayName=Doe, John);" _
& "cn,objectClass"

...and then apply the filter? I have tried the below without success:

oRS.Filter = "objectClass = 'contact'"
oRS.Filter = "objectClass = contact"
oRS.Filter = "objectClass LIKE 'contact'"

I have successfully used 'Filter' on existing recordsets when the
attribute is a single-valued string, but cannot figure out how to do it for
a multi-valued string. Is this supported? If so, can someone please provide
the proper syntax?




My System SpecsSystem Spec
Old 02-18-2009   #2 (permalink)
Richard Mueller [MVP]


 
 

Re: Filter existing recordset for objectClass

James Whitlow wrote:
Quote:

> Does anyone know if it is possible to filter an existing Active Directory
> recordset using the 'objectClass' attribute?
>
> I know I can do this:
>
> oRS.Open "<LDAP://" & sDomainDN & ">;(&(objectClass=contact)" _
> & "(displayName=Doe, John));cn,objectClass"
>
> But can I do this?:
>
> oRS.Open "<LDAP://" & sDomainDN & ">;(displayName=Doe, John);" _
> & "cn,objectClass"
>
> ...and then apply the filter? I have tried the below without success:
>
> oRS.Filter = "objectClass = 'contact'"
> oRS.Filter = "objectClass = contact"
> oRS.Filter = "objectClass LIKE 'contact'"
>
> I have successfully used 'Filter' on existing recordsets when the
> attribute is a single-valued string, but cannot figure out how to do it
> for a multi-valued string. Is this supported? If so, can someone please
> provide the proper syntax?
>
The following works for me (if sAMAccountName is included in the list of
attribute values in the recordset):

oRS.Filter = "(sAMAccountName='JDoe')"
or
oRS.Filter = "sAMAccountName='JDoe'"

But I cannot find a way to filter on objectClass using the Filter method of
the ADO recordset object. Note that the filter syntax in the original ADO
query uses LDAP syntax and is handled by the provider (ADsDSOObject). The
filter method of the ADO recordset object requires SQL syntax, where the
string value is enclosed in single quotes.

I conclude that the Filter method of the recordset cannot handle arrays. ADO
returns multi-valued attributes as an array of values. The objectCategory
property is single valued. In LDAP syntax you can use:

(objectCategory=person)

but in SQL syntax you must specify the full DN of the value in single
quotes, for example:

oRS.Filter =
"(objectCategory='cn=person,cn=Schema,cn=Configuration,dc=MyDomain,dc=com')"

The ADsDSOObject provider does a lot of work behind the scenes to make
things easy.

What are you trying to accomplish where you need to use the Filter method of
the recordset?

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


My System SpecsSystem Spec
Old 02-18-2009   #3 (permalink)
James Whitlow


 
 

Re: Filter existing recordset for objectClass

"Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote in
message news:eZfQBDekJHA.5836@xxxxxx
Quote:

> James Whitlow wrote:
>
Quote:

>> Does anyone know if it is possible to filter an existing Active
>> Directory recordset using the 'objectClass' attribute?
>>
>> I know I can do this:
>>
>> oRS.Open "<LDAP://" & sDomainDN & ">;(&(objectClass=contact)" _
>> & "(displayName=Doe, John));cn,objectClass"
>>
>> But can I do this?:
>>
>> oRS.Open "<LDAP://" & sDomainDN & ">;(displayName=Doe, John);" _
>> & "cn,objectClass"
>>
>> ...and then apply the filter? I have tried the below without success:
>>
>> oRS.Filter = "objectClass = 'contact'"
>> oRS.Filter = "objectClass = contact"
>> oRS.Filter = "objectClass LIKE 'contact'"
>>
>> I have successfully used 'Filter' on existing recordsets when the
>> attribute is a single-valued string, but cannot figure out how to do it
>> for a multi-valued string. Is this supported? If so, can someone please
>> provide the proper syntax?
>>
>
> The following works for me (if sAMAccountName is included in the list of
> attribute values in the recordset):
>
> oRS.Filter = "(sAMAccountName='JDoe')"
> or
> oRS.Filter = "sAMAccountName='JDoe'"
>
> But I cannot find a way to filter on objectClass using the Filter method
> of the ADO recordset object. Note that the filter syntax in the original
> ADO query uses LDAP syntax and is handled by the provider (ADsDSOObject).
> The filter method of the ADO recordset object requires SQL syntax, where
> the string value is enclosed in single quotes.
>
> I conclude that the Filter method of the recordset cannot handle arrays.
> ADO returns multi-valued attributes as an array of values. The
> objectCategory property is single valued. In LDAP syntax you can use:
>
> (objectCategory=person)
>
> but in SQL syntax you must specify the full DN of the value in single
> quotes, for example:
>
> oRS.Filter =
> "(objectCategory='cn=person,cn=Schema,cn=Configuration,dc=MyDomain,dc=com')"
>
> The ADsDSOObject provider does a lot of work behind the scenes to make
> things easy.
>
> What are you trying to accomplish where you need to use the Filter method
> of the recordset?
Thanks for the quick reply, Richard!

I am enumerating a list of names from another system in which I might have
both a contact and a user in AD (explanation too long for this
conversation). I am only considering my search to be a match if I get
exactly one record in my recordset. I am currently doing up to two searches,
one using 'objectClass=user'. If I get zero hits, I close by recordset and
re-open using 'objectClass=contact'. I want to speed things up by only
querying once. I can, of course not limit my search by 'objectClass' and
then search the 'objectClass' array. I was just hoping for a quick way out
using the 'Filter' method. Something along the lines of:

bMatch = False
oRS.Fiter = "objectClass = 'user'"
If oRS.Recordcount = 1 Then
bMatch = True
Else
oRS.Fiter = "objectClass = 'contact'"
If oRS.Recordcount = 1 Then bMatch = True
End If


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
how to write recordset datas of vbscript into existing excel sheet VB Script
run an UPDATE query on recordset VB Script
DBNull check for ADODB.recordset .NET General
Using a variable in a ADO recordset PowerShell
ADO recordset from standard in/out? PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46