"Expired or Invalid pagination request. Default Expiry time is 00:30:00" Error when returning 1000 or more entries with Get-User - Exchange Online Powershell V3 with Certificate Based Authentication

Ryan Graham 15 Reputation points
2023-06-01T16:11:38.1566667+00:00

Hello,

I'm upgrading my scripts to EXO v3.1.0 due to Microsoft's depreciation of version 2.0.5 at the end of June. Now, I'm running into an error with the below command.

$UserList = Get-User -ResultSize unlimited 

When I use certificate-based authentication for Exchange Online and the Get-User command returns over 1000 users, I get the below error every time: "Expired or Invalid pagination request. Default Expiry time is 00:30:00"

TerminatingError(Invoke-WebRequest): "{"error":{"code":"BadRequest","message":"Invalid Operation","innererror":{"message":"Invalid Operation","type":"Microsoft.Exchange.Admin.OData.Core.ODataServiceException","stacktrace":" at Microsoft.Exchange.AdminApi.CommandInvocation.CommandInvocation.InvokeCommand(QueryContext queryContext, CmdletInvokeInputType cmdletInvokeInputType)\r\n at Microsoft.Exchange.Admin.OData.Core.PathSegmentToExpressionTranslator.Translate(OperationImportSegment segment)\r\n at Microsoft.Exchange.Admin.OData.Core.QueryContext.ResolveQuery(ODataContext context, Int32 level)\r\n at Microsoft.Exchange.Admin.OData.Core.Handlers.OperationHandler.Process(IODataRequestMessage requestMessage, IODataResponseMessage responseMessage)\r\n at Microsoft.Exchange.Admin.OData.Core.Handlers.RequestHandler.Process(Stream requestStream)","internalexception":{"message":"Expired or Invalid pagination request. Default Expiry time is 00:30:00","type":"System.Exception","stacktrace":""}}}}"

The newer commands, like Get-ExoMailbox, work fine regardless of the number of users/objects. Any help would be greatly appreciated.

Exchange Online
Exchange Online
A Microsoft email and calendaring hosted service.
6,188 questions
{count} vote

3 answers

Sort by: Most helpful
  1. Lennard Lobrij 11 Reputation points
    2024-12-16T20:01:59.22+00:00

    For anyone still looking for a solution, I just retested this with ExchangeOnlineManagement version 3.7.0 and it now appears to be fixed.
    Adding -ResultSize Unlimited to for example Get-DistributionGroup or Get-Mailbox now returns all available results instead of the first 1000 results.

    1 person found this answer helpful.
    0 comments No comments

  2. Anonymous
    2023-06-02T08:38:24.6566667+00:00

    Hi @Ryan Graham ,

    I tried searching a lot but didn't find any official document explicitly stating if this is a limitation in V3. I've tried submitting feedback for your post below the documentation and we can see if we can get any more information there.

     https://github.com/MicrosoftDocs/office-docs-powershell/issues/10907

    Meanwhile, if you need to use "Get-user" urgently, you can uninstall the V3 module for the time being and install the old version V2.

    Best regards

    Shaofan


    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.  

    0 comments No comments

  3. Smith Pham 1,790 Reputation points Independent Advisor
    2025-05-07T10:40:03.8133333+00:00

    Dear Team,

    Limit Result Size and Paginate Manually

    If updating the module or switching to Get-ExoMailbox is not feasible, limit the result size to 1,000 or fewer objects per call and manually paginate through the results using a loop.

    Connect-ExchangeOnline -CertificateThumbprint "<Thumbprint>" -AppId "<AppId>" -Organization "<YourTenant>.onmicrosoft.com"
    $UserList = @()
    $BatchSize = 1000
    $Skip = 0
    do {
        $Batch = Get-User -ResultSize $BatchSize -Skip $Skip
        $UserList += $Batch
        $Skip += $BatchSize
    } while ($Batch.Count -eq $BatchSize)
    
    
    0 comments No comments

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.