VB.NET Return Active Directory UserNames

Using VB. NET. . . I created a program that randomly generates usernames. Now I need it to search the Active Directory to ensure the username does not already exist. How would I search my Active Directory to return a matching username? Also, how would I query Active Directory to return a listing of all usernames? T ...

Slack Space 1613 This topic was started by ,


data/avatar/default/avatar28.webp

295 Posts
Location -
Joined 2001-07-04
Using VB.NET...
 
I created a program that randomly generates usernames. Now I need it to search the Active Directory to ensure the username does not already exist. How would I search my Active Directory to return a matching username? Also, how would I query Active Directory to return a listing of all usernames? This was easy in VB6... but doesn't seem to be as straight-forward now.
 
Thanks in advance.

Participate on our website and join the conversation

You have already an account on our website? Use the link below to login.
Login
Create a new user account. Registration is free and takes only a few seconds.
Register
This topic is archived. New comments cannot be posted and votes cannot be cast.

Responses to this topic


data/avatar/default/avatar28.webp

295 Posts
Location -
Joined 2001-07-04
OP
It shouldn't matter, but yes... it's on a couple servers (mixed with 2k).
 
Either way, I figured it out. I'll post the code when I get off of work.

data/avatar/default/avatar12.webp

1915 Posts
Location -
Joined 2000-03-30
I misunderstood the questions.
 
 
I thought you were trying to query AD for specific users.
 
 
With Server 2003 you can use DSGET command
 
 
But since you are talking programming, thats not my thing

data/avatar/default/avatar28.webp

295 Posts
Location -
Joined 2001-07-04
OP
No problem. Here's what I found to work. It returns the user's name, their path, and also their alias (or username).
 

Code:
        Dim enTry As DirectoryEntry = New DirectoryEntry("LDAP://mydomain")        ''Console.Write(enTry.Username)        Dim mySearcher As DirectorySearcher = New DirectorySearcher(enTry)        mySearcher.Filter = "(objectClass=User)"        Dim resEnt As SearchResult        For Each resEnt In mySearcher.FindAll()            Console.WriteLine(resEnt.GetDirectoryEntry().Name.ToString())            Console.WriteLine(resEnt.GetDirectoryEntry().Properties("sAMAccountName").Value.ToString())            Console.WriteLine(resEnt.GetDirectoryEntry().Path.ToString())            Console.WriteLine(resEnt.GetDirectoryEntry().NativeGuid.ToString())            Console.WriteLine("===========================================")        Next