In Exchange, when running a the search-mailbox command and you have a large user base, you might encounter the following error:

Sending data to a remote command failed with the following error message: The total data received from the remote clien
t exceeded allowed maximum. Allowed maximum is 524288000. For more information, see the about_Remote_Troubleshooting Help topic.+ CategoryInfo : OperationStopped: (System.Manageme…pressionSyncJob:PSInvokeExpressionSyncJob) [], PSRemotingTransportException
+ FullyQualifiedErrorId : JobFailure

The error takes a while to show but unfortunately it has reached a default limit which cannot be changed.

Don’t worry, there are some workarounds which can get you through this, here are some of them:

  • You can add this into a foreach statement to loop through each mailbox at a time
  • You could run the command against each mailbox server, however if you have hundreds of servers it might not be an option.
  • You can lastly create a new¬†PSSessionConfiguration on your remote server where you running this, however you might also hit a memory quota error.
  • Changing your Search Query by shortening the date range.

To expand on the above, you can use the following command below to create a foreach statement to loop though the mailboxes:

ForEach Statement:

$Users = Get-Content "C:\Users\User\Script\Users.csv"
foreach ($User in $Users)
{
	Get-Mailbox -Identity $User | Search-Mailbox -SearchQuery "Received:> $("2016-06-15 00:00:00") AND Received:< $("2016-07-01 00:00:00")" -targetmailbox domain\mailbox -TargetFolder Search1 -LogLevel full
}

vs the standard command to search the mailbox:

Get-Mailbox -ResultSize unlimited -OrganizationalUnit 'domain.local/OU/domain.com' | Search-Mailbox -SearchQuery "Received:> $("2016-06-15 00:00:00") AND Received:< $("2016-07-01 00:00:00")" -targetmailbox domain\mailbox -TargetFolder Search1 -LogLevel full

Using an Individual mailbox server:

Get-MailboxServer -Identity Server1 | Get-Mailbox -ResultSize unlimited -OrganizationalUnit 'domain.local/OU/domain.com' | Search-Mailbox -SearchQuery "Received:> $("2016-06-15 00:00:00") AND Received:< $("2016-07-01 00:00:00")" -targetmailbox domain\mailbox -TargetFolder Search1 -LogLevel full

Creating a new PSSessionConfiguration, this includes 3 commands:

Register-PSSessionConfiguration -Name CustomLimits
Set-PSSessionConfiguration -Name CustomLimits -MaximumReceivedDataSizePerCommandMB 500 -MaximumReceivedObjectSizeMB 500
$Session = New-PSSession -ComputerName Server2 -ConfigurationName CustomLimits

If you still getting errors then try and change your search, shortening the date range.

The ForEach Script is located on TechNet Gallery using this link.

Hope it helps.

Advertisements
Advertisements