Retrieve GUID on all users in Active Directory

I currently pull a list of all the Active Directory users on the network.  
What I need now is their GUID.  
The GUID is the same for every user.  So I don't think it's correct.  

Here's the code.
Dim userEntry As DirectoryEntry
userEntry = New DirectoryEntry("LDAP://")

Dim ADEntry As New System.DirectoryServices.DirectoryEntry("WinNT://")

For Each userEntry In ADEntry.Children
    Dim thisGuid As String
    Dim oGuid As Guid

    If userEntry.SchemaClassName = "User" Then
      oGuid = userEntry.Guid
      thisGuid = oGuid.ToString
      Response.Write(userEntry.Properties("FullName").Value.ToString & " / " & userEntry.Name.ToString & " / " & thisGuid & "<br>")

    End If

I'm using ASP.NET 4.0 VB web app.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chris DentPowerShell DeveloperCommented:
Use the DirectorySearcher and request the objectGUID attribute.
Dim SearchRoot as New DirectoryEntry()
Dim Searcher As New DirectorySearcher(SearchRoot, "(&(objectClass=user)(objectCategory=person))")
' Searcher.PageSize = 1000
Searcher.SizeLimit = 10

For Each Result As SearchResult In Searcher.FindAll()
  Dim GuidBytes() As Byte = Result.Properties("objectguid")(0)
  Dim objectGuid As New Guid(GuidBytes)

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jshesekAuthor Commented:
Worked really well - Thanks
The code shows where you add in the different properties that you need into the Searcher.

Then you can pull the data out for use
Dim GuidBytes() As Byte = Result.Properties("objectguid")(0)
Dim thisUser As String = Result.Properties("Name")(0)
Dim objectGuid As New Guid(GuidBytes)
If (InStr(thisUser, ",") > 0) Then
      Response.Write(objectGuid.ToString() & " _  " & thisUser & "<br>")
End If

If you know of any good links, for better learning, on this, I'd appreciate it if you would share.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.