Expired or Invalid pagination request

Rajeev Kumar 0 Reputation points
2025-04-24T06:05:54.82+00:00

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

At C:\Users\127079\AppData\Local\Temp\tmpEXO_nyok0szv.zqj\tmpEXO_nyok0szv.zqj.psm1:1189 char:13

  •         Write-ErrorMessage $ErrorObject
    
  •         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : NotSpecified: (:) [Get-Mailbox], Exception
    • FullyQualifiedErrorId : [Server=SA1PR12MB8164,RequestId=d768472c-04fa-42f6-43db-62c7e24b1e80,TimeStamp=Thu, 24 Apr 2025
    05:54:08 GMT],Write-ErrorMessage
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,924 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Smith Pham 0 Reputation points
    2025-05-01T11:25:40.0333333+00:00
    1. Reduce Query Scope:
      • Narrow the scope of the Get-Mailbox command to process fewer objects at a time (e.g., use filters like -Filter or -RecipientTypeDetails).
      • Example: powershellCopyGet-Mailbox -ResultSize 100 -Filter {RecipientTypeDetails -eq 'UserMailbox'}
    2. Increase Timeout Settings:
      • Adjust the timeout settings for the Exchange Online session to prevent session drops.
      • Example: powershellCopy$PSSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential (Get-Credential) -Authentication Basic -AllowRedirection Set-PSSessionOption -IdleTimeout 3600000
    3. Handle Pagination Properly:
      • If your script paginates results, ensure it processes each page within the 30-minute token expiry.
      • Use -ResultSize Unlimited cautiously, as it may exacerbate the issue with large datasets. Instead, paginate manually: powershellCopy$mailboxes = Get-Mailbox -ResultSize 1000 while ($mailboxes) { # Process mailboxes $mailboxes = Get-Mailbox -ResultSize 1000 -SkipToken $mailboxes.NextPageToken ``}
    4. Reconnect to Exchange Online:
      • Re-establish the session to refresh the pagination token: powershellCopyConnect-ExchangeOnline -UserPrincipalName <YourUPN> -ShowProgress $true
    5. Check for Script Errors:
      • Inspect the script at the referenced file (C:\Users\127079\AppData\Local\Temp\tmpEXO_nyok0szv.zqj\tmpEXO_nyok0szv.zqj.psm1:1189) for issues in how it handles errors or pagination.
      • Ensure the script isn't stuck in a loop or making excessive API calls.
    6. Update PowerShell Modules:
      • Ensure you’re using the latest version of the Exchange Online Management module: powershellCopyUpdate-Module -Name ExchangeOnlineManagement
    7. Monitor API Rate Limits:
      • Excessive API calls may lead to throttling. Check if your script is hitting rate limits and introduce delays if needed: powershellCopyStart-Sleep -Milliseconds 500
    8. Check Network Stability:
      • Verify your network connection is stable to avoid session interruptions.

    Additional Recommendations:

    • Error Logging: Add logging to your script to capture detailed error information for debugging: powershellCopytry { Get-Mailbox -ResultSize 1000 -ErrorAction Stop } catch { Write-Host "Error: $_" -ForegroundColor Red # Log to file $_ | Out-File -FilePath "C:\Logs\MailboxError.log" -Append ``}
    1. Reduce Query Scope:
      • Narrow the scope of the Get-Mailbox command to process fewer objects at a time (e.g., use filters like -Filter or -RecipientTypeDetails).
        - Example: powershellCopy`Get-Mailbox`` ``-ResultSize`` ``100`` ``-Filter`` {RecipientTypeDetails ``-eq`` ``'UserMailbox'``}` 
        
    2. Increase Timeout Settings:
    • Adjust the timeout settings for the Exchange Online session to prevent session drops.
      • Example: powershellCopy$PSSession`` = ``New-PSSession`` ``-ConfigurationName`` Microsoft.Exchange ``-ConnectionUri`` https://outlook.office365.com/powershell``-liveid``/ ``-Credential`` (``Get-Credential``) ``-Authentication`` Basic ``-AllowRedirection`` ``Set-PSSessionOption`` ``-IdleTimeout`` ``3600000
      1. Handle Pagination Properly:
        • If your script paginates results, ensure it processes each page within the 30-minute token expiry.
          - Use -ResultSize Unlimited cautiously, as it may exacerbate the issue with large datasets. Instead, paginate manually: powershellCopy`$mailboxes`` = ``Get-Mailbox`` ``-ResultSize`` ``1000`` ``while`` (``$mailboxes``) {     `*`# Process mailboxes`*`     ``$mailboxes`` = ``Get-Mailbox`` ``-ResultSize`` ``1000`` ``-SkipToken`` ``$mailboxes``.NextPageToken }` 
          
          1. **Reconnect to Exchange Online**: 
          
                - Re-establish the session to refresh the pagination token: powershellCopy`Connect-ExchangeOnline`` ``-UserPrincipalName`` <YourUPN> ``-ShowProgress`` ``$true` 
          
                1. **Check for Script Errors**: 
          
                      - Inspect the script at the referenced file (C:\Users\127079\AppData\Local\Temp\tmpEXO_nyok0szv.zqj\tmpEXO_nyok0szv.zqj.psm1:1189) for issues in how it handles errors or pagination.
          
                            - Ensure the script isn't stuck in a loop or making excessive API calls.
          
                            1. **Update PowerShell Modules**: 
          
                                  - Ensure you’re using the latest version of the Exchange Online Management module: powershellCopy`Update-Module`` ``-Name`` ExchangeOnlineManagement` 
          
                                  1. **Monitor API Rate Limits**: 
          
                                        - Excessive API calls may lead to throttling. Check if your script is hitting rate limits and introduce delays if needed: powershellCopy`Start-Sleep`` ``-Milliseconds`` ``500` 
          
                                        1. **Check Network Stability**: 
          
                                              - Verify your network connection is stable to avoid session interruptions.
          
                                              - Additional Recommendations:
          
    • Error Logging: Add logging to your script to capture detailed error information for debugging: powershellCopytry`` { ``Get-Mailbox`` ``-ResultSize`` ``1000`` ``-ErrorAction`` Stop } ``catch`` { ``Write-Host`` ``"Error: $_"`` ``-ForegroundColor`` Red # Log to file ``$_`` | ``Out-File`` ``-FilePath`` ``"C:\Logs\MailboxError.log"`` ``-Append`` }
    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.