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

How can I search Active Directory?

Status
Not open for further replies.

jmeckley

Programmer
Jul 15, 2002
5,269
US
I have Sql Server 2000 linked to Active Directory. From this I created a view of all the users and ADsPaths. Now in my appilcations I can query the Active Directory view and use the ADsPath to access information in Active Directory.

I want to cycle through the users and add their email address to an array if they are part of the group 'All Staff' (this will exclude resources with email addresses like confrence rooms and vehicles). Here is what I have so far:[tt]
RdrEmail = CmdEmail.ExecuteReader
While RdrEmail.Read
adUser = GetObject(RdrEmail.Item("ADsPath").GetType.ToString())
If adUser.AccountDisabled = False And adUser.Groups("All Staff") Then
Email.Add(adUser.EmailAddress)
End If
End While
RdrEmail.Close()
[/tt]
The underlined text is where I am getting a build error. The error is:[tt]Interface 'ActiveDs.IADsMembers' cannot be indexed because it has no default property.[/tt]

I have also tried [tt]adUser.Groups = "All Staff"[/tt]. From Groups you have 3 choices; Count, Filter, GetEnumerator. I searched their properties and methods as well, but haven't found anything.

How can I go about selecting users from certain groups? This would be the corner stone of setting user rights in applications

thanks for your help



Jason Meckley
Database Analyst
WITF
 
OK, first.. I am not running on a system that has AD, so I can't test this..
<snip>
adUser.Groups(&quot;All Staff&quot;)
</snip>
My guess is you need to add a property after the last &quot;)&quot;
I would try &quot;adUser.Groups(&quot;All Staff&quot;).Name&quot;
then &quot;adUser.Groups(&quot;All Staff&quot;).Value&quot;
then &quot;adUser.Groups(&quot;All Staff&quot;).toString&quot;
then &quot;adUser.Groups(&quot;All Staff&quot;).text&quot;

But without a system that can return this it is hard to say this is the one.. But I am trying to think of properties that would make sence to the developer fo the aduser.Groups object..

Good Luck

Rob
 
I tried that, but no luck. I have found this is probally more managable on the Sql Server side.

useful documentation seems slim to none. I have found basic queries, but can't find anything on advanced queries, like listing which groups a user belongs to. I would also like to find documention on the heirachry of AD and what possible values fields can have.

Jason Meckley
Database Analyst
WITF
 
How'd ya get SQL Server to connect to active directory? I have been looking to do this too.
 
execute this stored procedure.
[tt]sp_addlinkedserver 'ADSI', 'Active Directory Service Interfaces', 'ADSDSOObject', 'adsdatasource'[/tt]

This will allow you to reference AD by [tt]ADSI[/tt]. Here are some of the views I have created so far in my discoveries of AD.
[tt]SELECT TOP 100 PERCENT *
FROM OPENQUERY(ADSI, '<LDAP://W2KRoot>;(&(objectCategory=Person)(objectClass=user));name, adspath,;subtree') Rowset_1
ORDER BY name[/tt]
Selects all the entities who are have a class of user and category of person

[tt]SELECT TOP 100 PERCENT *
FROM OPENQUERY(ADSI, '<LDAP://W2KRoot>;(&objectClass=group);name, adspath,;subtree') Rowset_1
ORDER BY name[/tt]
Selects all the groups in active directory.

[tt]SELECT TOP 100 PERCENT *
FROM OPENQUERY(ADSI, '<LDAP://W2KRoot>;;name, adspath,;subtree') Rowset_1
ORDER BY name[/tt]
Selects everything in active directory.

I have read on MSDN that you cannot query a field with an array-based properity. ie: one to many relationship, like Members or MembersOf. here is the article At the end of the article is a section called Limitations. This explains is a little more detail. I also have a link to the attributes of AD. Our network supervisor found this reference.
I also have this issue posted in the sql server forum thread183-587842.

Jason Meckley
Database Analyst
WITF
 
I found a crude solution to my delemia. I posted my findings on the sql ser forum since it is realated to sql server more than ASP.Net
thread183-587842

Jason Meckley
Database Analyst
WITF
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top