Connect-ExchangeOnline: Write-ErrorMessage : Expired or Invalid pagination request. Default Expiry time is 00:30:00

Dane Briggs 211 Reputation points
2022-09-26T17:20:13.937+00:00

I wrote a script a while back that gets the the UserPrincipalName, DisplayName, LastLogonTime, CreationTime, Inactive Days, MailboxType, AssignedLicenses, ItemCount, MB Size, and Roles from MSOnline and Exchange Online. It works fine on one server and my laptop but it fails with the message below. The server that I run it from is being decommissioned so I need to move it to a new server. Why would the script work on a server and my laptop but nowhere else?

  PS>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":""}}}}"  
    Write-ErrorMessage : Expired or Invalid pagination request. Default Expiry time is 00:30:00  
    At C:\Users\Me\AppData\Local\Temp\tmpEXO_3gsqzody.faf\tmpEXO_3gsqzody.faf.psm1:1107 char:13  
    +             Write-ErrorMessage $ErrorObject $IsFromBatchingRequest  
    +             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
        + CategoryInfo          : NotSpecified: (:) [Get-Mailbox], Exception  
        + FullyQualifiedErrorId : [Server=DM6PR14MB4156,RequestId=ebb50db0-607b-668c-4603-4639ca0ba4c1,TimeStamp=Wed, 21   
    Sep 2022 18:52:31 GMT],Write-ErrorMessage  
    Write-ErrorMessage : Expired or Invalid pagination request. Default Expiry time is 00:30:00  
    At C:\Users\Me\AppData\Local\Temp\tmpEXO_3gsqzody.faf\tmpEXO_3gsqzody.faf.psm1:1107 char:13  
    +             Write-ErrorMessage $ErrorObject $IsFromBatchingRequest  
    +             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
        + CategoryInfo          : NotSpecified: (:) [Get-Mailbox], Exception  
        + FullyQualifiedErrorId : [Server=DM6PR14MB4156,RequestId=ebb50db0-607b-668c-4603-4639ca0ba4c1,TimeStamp=Wed, 21 Sep 2022 18:52:31 GMT],Write-Erro  
       rMessage  
      
  
Microsoft Exchange Online Management
Microsoft Exchange Online Management
Microsoft Exchange Online: A Microsoft email and calendaring hosted service.Management: The act or process of organizing, handling, directing or controlling something.
4,195 questions
Microsoft Exchange Hybrid Management
Microsoft Exchange Hybrid Management
Microsoft Exchange: Microsoft messaging and collaboration software.Hybrid Management: Organizing, handling, directing or controlling hybrid deployments.
1,896 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,382 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Aleh Alisevich 5 Reputation points
    2023-05-29T08:39:06.81+00:00

    have same issue, run a script and after 30 min in stops with error:

    Write-ErrorMessage : Expired or Invalid pagination request. Default Expiry time is 00:30:00
    At C:\Users\dmaa-t0\AppData\Local\Temp\21\tmpEXO_pha5tw53.per\tmpEXO_pha5tw53.per.psm1:1120 char:13
    +             Write-ErrorMessage $ErrorObject
    +             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [Get-UnifiedGroup], Exception
        + FullyQualifiedErrorId : [Server=DB8PR03MB6137,RequestId=cf88c852-180d-5b56-cd1b-8c9ad358856c,TimeStamp=Mon, 29 May 2023 08:28:22 GMT],Write-ErrorMessage
    
    
    1 person found this answer helpful.
    0 comments No comments

  2. Oliver 11 Reputation points
    2023-05-30T05:16:39.2133333+00:00

    When you send a command that returns more then 1.000 elements (e.g. Get-Mailbox in larger setups), the API endpoint returns the first 1.000 elements and a next link to the next page of 1.000 elements. This next link contains a skip token and helps the server to know where to continue. If the Powershell Module sends this second page request and you use certificate authentication like described in this article, it can happen that you immediately receive this timeout message. If this happens, please ensure you use the .onmicrosoft.com domain for the organization parameter and not a custom domain configured for your tenant.

    1 person found this answer helpful.

  3. Dane Briggs 211 Reputation points
    2022-09-30T21:07:14.97+00:00

    The script I was using was an old script that used Get-Mailbox and Get-MailboxStatistics which continued to fully function using ExchangeOnlineManagement Module V2. However, when I moved the script to a new server, I installed the newest ExchangeOnlineManagement Module, V3. It seems that Get-Mailbox and Get-MailboxStatistics have been limited on V3. I've updated my scripts to use Get-EXOMailbox and Get-EXOMailboxStatistics. Using the newer commands has resolved the issue.