![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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? > 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 Specs![]() |
| | #3 (permalink) |
| | 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? 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 Specs![]() |
![]() |
| 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 | |||