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

the script repo examples are almost entirely written in ADSI, however powershell is now far more widely used, is it possible to have all scripts written in both ADSI and powershell.

asked Jan 5 by i*windows (140 points)
0 votes
1 answer

We have a business rule that will update an AD attribute when a new member is added to a group. This business rule works when we use powershell commands or the admin console ... set to trigger "After adding a member to a group". Thank you for your support!

asked Mar 29, 2023 by mark.it.admin (2.3k points)
3,326 questions
3,026 answers
7,727 comments
544,684 users