09-07-20 01:04 PM
Working in Blue Prisms vb.net environment and currently building out an LDAP VBO utility. I have the below code, it will return the list of users in an AD Group i.e. samAccountName
, givenname
& surname
.
My namespace imports used are:
System
System.Drawing, System.Data
System.DirectoryServices
System.Collections.Generic
My issue is with trying to loop through the resultset and store each row of data returned in my final collection data item, colResults
.
I know I'm working with a collection and I'm aware that what I'm doing in my For Each loop is not correct, i.e. compile error:
"String cannot be converted to System.Data.Datatable"
But I'm unable to resolve.
I've attempted to rewrite and use an index but syntactically I can't use .Count
with my Properties.SearchResultCollection
.
Dim de As New DirectoryServices.DirectoryEntry("LDAP://" + Path)
Dim ds As New DirectoryServices.DirectorySearcher(de)
Dim srCol As DirectoryServices.SearchResultCollection
Dim sr As DirectoryServices.SearchResult
'Try and assume success
Success = True
Try
ds.Filter = "(&(objectCategory=user)(memberOf=" + GroupDN + "))"
ds.PropertiesToLoad.Add("givenname")
ds.PropertiesToLoad.Add("sn")
ds.PropertiesToLoad.Add("samAccountName")
srCol = ds.FindAll()
For Each sr In srCol
If Not sr.GetDirectoryEntry.Properties("name").Value Is Nothing Then
colResults = (sr.GetDirectoryEntry.Properties("givenname").Value.ToString())
colResults = (sr.GetDirectoryEntry.Properties("sn").Value.ToString())
colResults = (sr.GetDirectoryEntry.Properties("samAccountName").Value.ToString)
End If
Next
Catch e As System.Exception
Success = False
End Try
--------------------------------------------------