PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,924 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Get-Mailbox -ResultSize 100 -Filter {RecipientTypeDetails -eq 'UserMailbox'}
$PSSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential (Get-Credential) -Authentication Basic -AllowRedirection Set-PSSessionOption -IdleTimeout 3600000
$mailboxes = Get-Mailbox -ResultSize 1000 while ($mailboxes) {
# Process mailboxes
$mailboxes = Get-Mailbox -ResultSize 1000 -SkipToken $mailboxes.NextPageToken ``}
Connect-ExchangeOnline -UserPrincipalName <YourUPN> -ShowProgress $true
Update-Module -Name ExchangeOnlineManagement
Start-Sleep -Milliseconds 500
Additional Recommendations:
try { Get-Mailbox -ResultSize 1000 -ErrorAction Stop } catch { Write-Host "Error: $_" -ForegroundColor Red
# Log to file
$_ | Out-File -FilePath "C:\Logs\MailboxError.log" -Append ``}
- Example: powershellCopy`Get-Mailbox`` ``-ResultSize`` ``100`` ``-Filter`` {RecipientTypeDetails ``-eq`` ``'UserMailbox'``}`
$PSSession`` = ``New-PSSession`` ``-ConfigurationName`` Microsoft.Exchange ``-ConnectionUri`` https://outlook.office365.com/powershell``-liveid``/ ``-Credential`` (``Get-Credential``) ``-Authentication`` Basic ``-AllowRedirection`` ``Set-PSSessionOption`` ``-IdleTimeout`` ``3600000
- 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:
try`` { ``Get-Mailbox`` ``-ResultSize`` ``1000`` ``-ErrorAction`` Stop } ``catch`` { ``Write-Host`` ``"Error: $_"`` ``-ForegroundColor`` Red
# Log to file
``$_`` | ``Out-File`` ``-FilePath`` ``"C:\Logs\MailboxError.log"`` ``-Append`` }