Solved

How do I list all property names in a VB.net LDAP connection?

Posted on 2011-09-07
4
577 Views
Last Modified: 2012-05-12
Hello folks.  What I need to do is query my AD and get a list of all available property names for each user in my AD.   (like First Name, Last Name...etc..etc..) (not that actual values for each property, but the property names themselves) There are some custom tabs when you look at a user acct in my active directory users and computers and I don't know the actual name of them to be able to reference them in my code.  I can easily get the values for things like "givenname" and "mail", however I simply want to retrieve a list of all of the possible property names so I can query any individual one for it's value for a specific user.  
Below is the code i'm using to connect to LDAP.  Can anyone add to or modify the code below allowing me to properly display what i'm needing?

thanks again!

Dim oSearcher As New DirectorySearcher
        Dim oResults As SearchResultCollection
        Dim oResult As SearchResult
        Dim RetArray As New ArrayList
        Dim mCount As Integer
        Dim mIdx As Integer
        Dim mLDAPRecord As String

        Dim ResultFields() As String = {"securityEquals", "cn"}

        Try
            With oSearcher

                .SearchRoot = New DirectoryEntry("LDAP://client.mydomain.net/DC=client,DC=mydomain,DC=net")
                .PropertiesToLoad.AddRange(ResultFields)
                '.Filter = "cn=" & pFindWhat & "*"
                .Filter = "givenname=" & pFindWhat & "*"
                oResults = .FindAll()

            End With

Open in new window


for example, the image below has your common properties shown for a user in AD.  I think those are the standard properties and I have some custom tabs that have more properties similar to below.  How do I get the actual names used to reference them in code so as to retrieve it's value?
 ldap
0
Comment
Question by:linuxrox
  • 2
4 Comments
 
LVL 28

Expert Comment

by:strickdd
Comment Utility
You need to use Reflection to do this. Here is an example that I've worked from in the past. You just need to update it to suit your needs (i.e., change the object being reflected)

http://www.vb-helper.com/howto_net_system_information.html
0
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
The DirectoryEntry class has a Properties collection.

Function to Print DirectoryEntry properties
http://geekswithblogs.net/mnf/archive/2006/04/20/75646.aspx
Public Shared Sub PrintDirectoryEntryProperties(entry As System.DirectoryServices.DirectoryEntry, sComment As String)
	' loop through all the properties and get the key for each
	For Each Key As String In entry.Properties.PropertyNames
		Dim sPropertyValues As String = [String].Empty
		' now loop through all the values in the property;
		' can be a multi-value property
		For Each Value As Object In entry.Properties(Key)
			sPropertyValues += Convert.ToString(Value) & ";"
		Next
		' cut off the separator at the end of the value list
		sPropertyValues = sPropertyValues.Substring(0, sPropertyValues.Length - 1)
		' now add the property info to the property list
		Debug.WriteLine(Key & "=" & sPropertyValues)
	Next
End Sub

Open in new window

0
 

Author Comment

by:linuxrox
Comment Utility
interesting.  I just don't know what the object is called that I am supposed to use.
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
Comment Utility
Oh, yes, you are using SearchResult, which has the Properties collection, too:

SearchResult.Properties Property
http://msdn.microsoft.com/en-us/library/system.directoryservices.searchresult.properties.aspx
' Get the properties for 'mySearchResult'.
Dim myResultPropColl As ResultPropertyCollection
myResultPropColl = mySearchResult.Properties
Console.WriteLine("The properties of the 'mySearchResult' are :")
Dim myKey As String
For Each myKey In  myResultPropColl.PropertyNames
   Dim tab1 As String = "    "
   Console.WriteLine(myKey + " = ")
   Dim myCollection As Object
   For Each myCollection In  myResultPropColl(myKey)
      Console.WriteLine(tab1 + myCollection)
   Next myCollection
Next myKey

Open in new window

0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now