When running operations in the Exchange Management Shell, you may run into the situation where the commands do not complete and the error “Pipeline not executed because a pipeline is already executing” is reported. An example of this is shown below. This is an Exchange 2010 SP3 RU15 lab server. In this case a PowerShell one-liner was used to iterate through the Exchange 2010 servers, and to start any services that were on the ServicesNotRunning list. This script and others feature in a previous post.
Get-ExchangeServer | FOREACH {$Srv =$_.Name; Write-Host $Srv -ForegroundColor Magenta (Test-ServiceHealth -Server $_ | Select-Object ServicesNotRunning -Expand ServicesNotrunning | Set-Service -ComputerName $Srv -Status Running )}
For the benefit of the search engines the error details are also included:
Get-ExchangeServer | FOREACH {$Srv =$_.Name; Write-Host $Srv -ForegroundColor Magenta (Test-ServiceHealth -Server $_ |
Select-Object ServicesNotRunning -Expand ServicesNotrunning )}
Pipeline not executed because a pipeline is already executing. Pipelines cannot be executed concurrently.
+ CategoryInfo : OperationStopped: (Microsoft.Power...tHelperRunspace:ExecutionCmdletHelperRunspace) [], PSInvalidO
perationException
+ FullyQualifiedErrorId : RemotePipelineExecutionFailed
Pipeline not executed because a pipeline is already executing. Pipelines cannot be executed concurrently.
+ CategoryInfo : OperationStopped: (Microsoft.Power...tHelperRunspace:ExecutionCmdletHelperRunspace) [], PSInvalidO
perationException
+ FullyQualifiedErrorId : RemotePipelineExecutionFailed
Exchange 2010 and onwards use PowerShell remoting. In the above Exchange 2010, cannot process two pipelines simultaneously hence we get the error. This is typically caused by the pipe to the FOREACH-Object. There are a couple of ways to address this:
- If the cmdlet that you are piping to supports the objects being passed to it, then it may be possible to remove the FOREACH
- Simplify the command to remove the FOREACH running with multiple pipelines. Save the initial collection as a variable, and then process the variable
We will look at the second option. Rather than running the single one-line that was initially attempted, it will be split into two separate lines.
$Servers = Get-ExchangeServer
$Servers | FOREACH {$Srv =$_.Name; Write-Host $Srv -ForegroundColor Magenta (Test-ServiceHealth -Server $_ | Select-Object ServicesNotRunning -Expand ServicesNotrunning | Set-Service -ComputerName $Srv -Status Running )}
In the above screenshot we can see that the operation was successful, and that the command did actually reach out and start the required services.
Bootnote
With the newer builds of Exchange and PowerShell I have seen this issue less and less. Maybe because I am doing more scripts. Maybe my memory is failing…
And also directly importing the PSSnapin is not supported with Exchange 2010 onwards unless you are following a specific documented process by Microsoft support.
Cheers,
Rhoderick