Data in the command exceeded the maximum permitted by the session configuration error when running Get-Mailbox -ResultSize Unlimited
Original KB number: 2922668
Symptoms
When you use the remote Exchange PowerShell command Get-Mailbox -ResultSize Unlimited to retrieve information about Exchange Online mailboxes in your organization, you receive an error message that resembles the following:
[ClientAccessServer=XXXXXXXXXCA014,
BackEndServer=XXXXXXmb294.namprd05.prod.outlook.com
,RequestId=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx,TimeStamp=<Date><Time>] The data in the command exceeded the maximum permitted by the session configuration. The allowed maximum is 500MB. Change the input, use a different session configuration, or change the "PSMaximumReceivedObjectSizeMB" and "PSMaximumReceivedDataSizePerCommandMB" properties of the session configuration on the remote computer
Cause
This issue occurs when the process times out as it tries to retrieve a large volume of data in one session. This issue may occur when you try to retrieve mailbox information from a very large organization.
Workaround
To work around this issue, run the command to execute on the server, and then add a pause between each command to prevent throttling.
Step 1 - Retrieve the list of objects from the server
Use the Invoke-Command
cmdlet to execute the commands from the server. For example:
$mailboxes = Invoke-Command -Session (Get-PSSession) -ScriptBlock {Get-Mailbox -ResultSize Unlimited | Select-Object -Property Identity,DisplayName}
Step 2 - Add a pause between each command
Use the Start-Sleep
cmdlet to add a pause between each object that's being processed. For example:
foreach($m in $mailboxes) {Get-MailboxPermission $m.Identity.ToString() | Where { ($_.AccessRights -eq "FullAccess") -and ($_.IsInherited -eq $False) -and -not ($_.User -like "NT AUTHORITY\SELF")}; Start-Sleep -Milliseconds 500}
More information
For more information, see the following Microsoft TechNet resources:
Still need help? Go to Microsoft Community.
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for