By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,949 Members | 1,077 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,949 IT Pros & Developers. It's quick & easy.

Active directory search through vbnet

P: 1
Hello, I am in the process of making a diagnostic program for our client machines and I am trying to get the container name as it contains the OU of the machine. I am able to do a search through vbnet but it only results in the computer name.
Dim ENTRY As System.DirectoryServices.DirectoryEntry = New
System.DirectoryServices.DirectoryEntry("LDAP://OU=Offices, DC=Test,DC=COM")

Dim MYSEARCHER As System.DirectoryServices.DirectorySearcher = New
MYSEARCHER.Filter = ("(&(objectclass=computer)(name=" + + ")) ")
Dim resEnt As System.DirectoryServices.SearchResult

For Each resEnt In MYSEARCHER.FindAll()


Console.WriteLine(":Processing:" &
Mid(resEnt.GetDirectoryEntry().Name.ToString(), 4))

Catch ex As Exception

Console.WriteLine("Trying to Connect to: " &
resEnt.GetDirectoryEntry().Name.ToString() & vbCrLf & ex.Message.ToString())

End Try

Mar 7 '17 #1
Share this Question
Share on Google+
1 Reply

P: 299
You need to tell your searcher to load AD properties. You can do so with this line, which will get all properties:
Expand|Select|Wrap|Line Numbers
  1. MYSEARCHER.PropertiesToLoad.Add("*")
After that, you can get a specific property by doing the following within your For loop, where "DistinguishedName" is the attribute you wish to get:
Expand|Select|Wrap|Line Numbers
  1. Dim DN As String = resent.Properties("DistinguishedName")(0)
Mar 7 '17 #2

Post your reply

Sign in to post your reply or Sign up for a free account.