DirectoryServices - Get users from active directory
Hello!
I'm using the following code to get the users of a specific active directory, but it also returns the computer names. How can I get the users only?
| | Dim myDirectoryAsNew DirectoryEntry("LDAP://" & directoryName, sAdminUser, sAdminPassword) Dim mySearcherAsNew DirectorySearcher(myDirectory) mySearcher.Filter ="(&(objectClass=user)(objectClass=person))" Dim mySearchResultCollAs SearchResultCollection = mySearcher.FindAll() ForEach mySearchResultAs SearchResultIn mySearchResultColl ..... Next
|
[1118 byte] By [
papadi] at [2007-12-16]
I don't know how to get the username returned on its own from Directory Services but this is how I did it (a while back, admittedly).
The value this function returns is [Computer Name]/[UserName], I believe... you simply do a substring with the starting position defined as (IndexOf("/") + 1).
You answering a completely different question! Here is what my code returns:
user1
user2
computer1
computer2
user3
computer4
user5
user6
I want to find out how it will return:
user1
user2
user3
user5
user6
i.e. without computers!!!
Ah! Now I follow you..! Sorry about the misunderstanding.
I suspect the problem is in your filter. Try running it just with (&objectClass=user) and not the person one. I'll have a go in the meantime to see if I can re-produce your bug.
It would be interesting to know if Paul_G's suggestion works; however, I think that computer accounts can be distinguished from user accounts primarily in that computer accounts end in "$". I hope that Paul's "culture" code provides a more trustworthy differentiator.
"(sAMAccountType=805306369)" "(sAMAccountType=805306368)"
One of those two types is computer.. the other is user. Either can be used as a filter. Who knows..
maybe you'll want Groups too, so here is the filter for all groups.
"(objectCategory=group)"