When working in the Exchange Management Shell in Exchange Server 2010, you may run into the following error:

Pipeline not executed because a pipeline is already executing. Pipelines cannot be executed concurrently.
+ CategoryInfo : OperationStopped: (Microsoft.Power…tHelperRuns
pace:ExecutionCmdletHelperRunspace) [], PSInvalidOperationException
+ FullyQualifiedErrorId : RemotePipelineExecutionFailed

This error is caused when executing the Exchange cmdlets through PowerShell remoting, which do not support more than one pipeline running at the same time. You may see this error when you pipe the output from a cmdlet to foreach-object, which then runs another cmdlet within its scriptblock.

A Simple Example

Although, you may encounter this error running any of the cmdlets, this a typical scenario:

You can see here we are piping the output of Get-Mailbox to foreach-object and attempting to run the Set-Mailbox cmdlet. We’re getting an error trying to set the max send size on all of the mailboxes to 10MB.

The Set-Mailbox cmdlet is designed to accept pipeline input from Get-Mailbox, so there is no need to use foreach-object. You just need to pipe Get-Mailbox to Set-Mailbox:

Get-Mailbox | Set-Mailbox -MaxSendSize 10MB

In this case, we’re able to work around the error easily since these cmdlets are designed to work together. The Set-Mailbox cmdlet gladly accepts pipeline input from the Get-Mailbox cmdlet, so there’s no need to loop through the results using foreach-object.

A Typical Example

Most of the time you’ll probably run into this when working with dissimilar cmdlets. Let’s say we want to create Inbox Rules for all the mailboxes in the Sales OU. Typically, you’d just retrieve all the mailboxes in the Sales OU using the Get-Mailbox cmdlet and pipe the results to the New-InboxRule cmdlet, like so:

[PS] C:\>Get-Mailbox -OrganizationalUnit Sales | ForEach-Object{
>>   New-InboxRule -Name Attach `
>>   -Mailbox $_ `
>>   -HasAttachment $true `
>>   -MarkImportance High
>> }
>>
Pipeline not executed because a pipeline is already executing. 
Pipelines cannot be executed concurrently.
    + CategoryInfo          : OperationStopped: 
(Microsoft.Power...tHelperRunspace:ExecutionCmdletHelperRunspace) [],
   PSInvalidOperationException
    + FullyQualifiedErrorId : RemotePipelineExecutionFailed

From the output, you can see that this this throws a concurrent pipeline error. To workaround the issue in this scenario, it becomes a two step process. First, we need to save the results of the Get-Mailbox cmdlet to a variable. Then we can pipe the variable to foreach-object:

$sales = Get-Mailbox -OrganizationalUnit Sales
$sales | ForEach-Object{
  New-InboxRule -Name Attach `
  -Mailbox $_ `
  -HasAttachment $true `
  -MarkImportance High
}

Since we’re piping the collection of mailboxes saved in the $sales variable to foreach-object, we’re only executing one pipeline per mailbox at a time.

Bypassing Remoting

Although, not supported, you could load the Exchange snap-in from a machine with the Exchange tools installed and bypass remoting, but I would recommend just fixing the problem by using the syntax shown in the previous example. Keep in mind that this isn’t actually supported and if you load the snap-in and do not use remoting, then RBAC is bypassed and you’ll need the appropriate AD permissions to make changes.

Ok now that I’ve put the disclaimer out there, you can do this by starting a standard PowerShell instance on a machine with the Exchange tools installed and loading the Exchange PSSnapin using the Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 command:

Hope this helps!