0 votes

I could not find an example of an ADSI API paged search, and learned the following through trial-and-error (using VB.NET). LDAP searches are limited to 1000 results per 'page', use multiple pages to get all results. Please comment if you can improve.

Dim strUserName, strPwd as string
Dim intPageSize as integer
Dim dtUser as dataTable
Dim drUser as dataRow

Dim adsNamespace As AdmNamespace = New AdmNamespace()
Dim admService As IAdmService = adsNamespace.GetNearestService("d2.waukco.gov"), strUserName, strPwd)

Dim admDirectorySearcher As IAdmDirectorySearcher = CType( admService.OpenObject(
"Adaxes://OU=UserAccounts,DC=d2,DC=waukco,DC=gov", strUserName, strPwd, 0),
IAdmDirectorySearcher)
admDirectorySearcher.SearchFilter = "(&(objectCategory=person)(objectClass=user))"
admDirectorySearcher.SetPropertiesToLoad(New String() {"department", "cn"})
admDirectorySearcher.PagingInfo = New AdmSearchPagingInfo(1, intPageSize)
admDirectorySearcher.ReferralChasing = ADS_CHASE_REFERRALS_ENUM.ADS_CHASE_REFERRALS_NEVER

{ define datatable dtUser}

Dim admSearchResultIterator As IAdmSearchResultIterator
Try
While True
admSearchResultIterator = admDirectorySearcher.ExecuteSearch()
If admSearchResultIterator.Count = 0 Then Exit While

For Each admSearchResult As AdmSearchResult In admSearchResultIterator.FetchAll()
drUser = dtUser.NewRow
drUser("department") = admSearchResult.Properties( "department").Value.ToString
drUser("cn") = admSearchResult.Properties( "cn").Value.ToString
dtUser.Rows.Add(drUser)
Next

admDirectorySearcher.PagingInfo = New AdmSearchPagingInfo(
admSearchResultIterator.ResultPagingInfo.Offset + intPageSize,
intPageSize, admSearchResultIterator.ResultPagingInfo.GetCookie)

End While

Catch ex As Exception
Dim strErr As String = ex.Message

Finally
If Not IsNothing(admSearchResultIterator) Then admSearchResultIterator.Dispose()
End Try

by (40 points)

Please log in or register to answer this question.

Related questions

0 votes
1 answer

Any idea why Softerra.Adaxes.Adsi.Search.DirectorySearcher is not getting loaded? PS C:\Windows\system32> [Reflection.Assembly]:: ... Object], PSArgumentException + FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand

asked Aug 14, 2019 by Brajesh (460 points)
0 votes
1 answer

Hallo, I'm trying to build a function that will have two parameters $Containrer and $Filter $filter - is a LDAP filer that serach some specific objects $Containrer - is a ... is treated by powershell as a hash table, is it possible to workoroud it somhow?

asked Aug 12, 2015 by axmaster (510 points)
0 votes
1 answer

Hello! We are currently trying to use the REST API to search for all group objects in our domain, but the search result is only returning 1000 objects. We tried supplying a ... the request. Is there a way to retrieve more than 1000 objects using the REST API?

asked Feb 16, 2022 by KelseaIT (320 points)
0 votes
1 answer

We try to use ADSI scripting to automate some tasks using Adaxes 2023. One such task is to try to check whether an answer provided by a user to his question is correct or not. ... . But I do not see an easy way to do this using ADSI script and/or interfaces.

asked Oct 22 by gfang (20 points)
0 votes
1 answer

Code is below. But the subject says it all. When I run the command targeted in this function via the Adaxes GUI or the web interface, it runs without issue. When run using this ... = $null } } end { $admNS = $admService = $credUser = $credPwd = $null } }

asked Apr 3 by jrtolle (20 points)
3,589 questions
3,278 answers
8,303 comments
548,155 users