How to get Mailbox list in batches of 100 using -ResultSize

Yash Vora 20 Reputation points
2026-06-03T12:57:42.23+00:00

I have to fetch Exchange Mailboxes in batches of 100 (there are total 1m+ mailboxes in organization).

I am using the following powershell command:

Get-EXOCASMailbox -ResultSize Unlimited

This gives me all the mailboxes which is taking long time. I can process the result in batches of 100 so I hit this command: Get-EXOCASMailbox -ResultSize 100

Seems to work fine but I'm stuck on how to bring the next 100 mailboxes.

PS: You can assume that the mailboxes are static and no changes will be made on them for indefinite time...

Exchange Online
Exchange Online

A cloud-based service included in Microsoft 365, delivering scalable messaging and collaboration features with simplified management and automatic updates.

0 comments No comments

Answer accepted by question author
Anonymous
2026-06-03T13:37:57.22+00:00

Hi   Yash Vora 

In theory, -ResultSize Unlimited should return all mailboxes in your organization. 

However, since your environment contains more than 1 million mailboxes, using -ResultSize Unlimited alone may not be practical, as it can be impacted by disk capacity and throughput limitations. 

With that in mind, I would recommend applying additional filters based on specific attributes such as: 

  • Department 
  • RecipientTypeDetails 

This approach can help narrow down the results and make the query more manageable. You can then export each filtered result into separate CSV files for easier review and future reference. 

For example, you may add the following after your PowerShell command Get-EXOCASMailbox: 

| Export-Csv -Path "C:\Temp\EXOCASMailbox.csv" -NoTypeInformation -Encoding UTF 

 For more detailed guidance, you may refer to: Export-Csv (Microsoft.PowerShell.Utility) - PowerShell | Microsoft Learn 

 

I hope this information provides helpful direction and adds further clarity. 


If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". 

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

2 additional answers

Sort by: Oldest
  1. AI answer

    2026-06-03T12:57:53.9266667+00:00

    -ResultSize limits how many objects the cmdlet returns, but it does not provide paging or a way to ask for “the next 100” directly. Each call starts again from the beginning of the result set.

    To process in batches of 100, retrieve all mailboxes once, then batch them in PowerShell:

    # Get all CAS mailboxes once
    $mailboxes = Get-EXOCASMailbox -ResultSize Unlimited
    
    # Process in batches of 100
    $mailboxes | ForEach-Object -Begin {
        $batch = @()
    } -Process {
        $batch += $_
        if ($batch.Count -eq 100) {
            # Do work on this batch of 100
            $batch | <# your processing here #>
    
            # reset batch
            $batch = @()
        }
    } -End {
        # process any remaining items (< 100)
        if ($batch.Count -gt 0) {
            $batch | <# your processing here #>
        }
    }
    

    If the goal is to reduce the time and data volume per call, use filters or property sets to narrow what Get-EXOCASMailbox returns, but paging still must be implemented client-side as above.

    For mailbox objects (not CAS settings), the same batching pattern applies with Get-EXOMailbox -ResultSize Unlimited.


    References:

    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

  2. Vasil Michev 128.1K Reputation points MVP Volunteer Moderator
    2026-06-03T13:41:57.73+00:00

    The cmdlets themselves do not support pagination, but the underlying API does. So if for some reason you absolutely must use pagination, I'd suggest you take a look at https://michev.info/blog/post/5822/all-you-need-to-know-about-exchange-online-admin-api-or-how-to-run-cmdlets-without-powershell

    In the request, set the Prefer header with value of odata.maxpagesize=100. And remember to follow the @odata.nextLink URLs :)

    Was this answer helpful?

    0 comments No comments

Your answer

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