vb.net pulling data from Active Directory using GC:// not LDAP://

Ryan Lashway 61 Reputation points
2023-01-10T14:30:02.727+00:00

I have the following code and this works, but I can not pull the additional PropertiesToLoad.Add values without it giving me blank records instead of data.

When I run the below code it will list all devices/objects in an OU, but if I add "disabled", "FullName" or any other AD attribute it just returns the correct number of records but no data for them.

I have to use GC:// as LDAP is not authorized on our network.

Try
dgview_ADUserListing.Rows.Clear() ' Clearing datagridview previous values
Dim rootentry as New DirectoryEntry("GC://" & SelectedContainerValue.Text) 'selected containervalue is a textbox populated via a click event on a treeview
Dim searcher as New DirectorySearcher(rootentry)
searcher.PropertiesToLoad.Add("canonicalName")
searcher.PropertiesToLoad.Add("fullname")
searcher.PropertiesToLoad.Add("Name")
searcher.PropertiesToLoad.Add("Disabled")

Dim results as SearchResultCollection
results = searcher.FindAll()
Dim ResultOU, ItemFullName, ItemName as String
Dim itemDisabled as Boolean
Dim result as SearchResult


For Each result in results
ResultOU= result.Properties("canonicalName")(0)
ItemName = result.Properties("name")(0).ToString()
dgview_ADUserListing.Rows.Add(ItemName, ResultOU)
Next
Developer technologies VB
{count} votes

1 answer

Sort by: Most helpful
  1. Michael Taylor 60,161 Reputation points
    2023-01-10T17:13:09.403+00:00

    I'm not sure what you mean by returning the correct # of records but no data. However if you ask for a property that doesn't exist then you get the result with no data. You didn't specify an example query nor whether you were using any filters so it is hard to confirm whether the properties you're searching for are actually defined or not. Perhaps you should consider using an AD explorer (like ADExplorer from Sysinternals) to see what the AD schema is.

    In my case if I filter on computers only then Disabled and fullName don't apply. name works though. This may just be a case of you trying to load properties that don't exist on the objects you're returning.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.