Kirk and Dmitry,
Thank you for your comments. I have reviewed your posts and the available information and here is what I have found.
You are correct in that Powershell will send information down the pipeline as soon as that information is available to do so. This is core to the architecture of Powershell. I should not have generalized the behavior of the get-mailbox cmdlet (and the other exchange cmdlets) to the behavior of Powershell. In this instance the get-mailbox cmdlet (and most other exchange cmdlets) operates by doing an ldap query to AD and is written in such a way that it will not pass any information down the pipeline until all of the results of the query have been returned. So this is a specific limitation of the get-mailbox cmdlet and is not generally how Powershell operates.
In a larger environment you will start processing mailboxes sooner and with fewer resources consumed if you execute the export-mailbox command only against a sub-set of users; rather than trying to execute against the entire set of users in the organization. Thus my “workaround” of using foreach to only operate on the users from one given server at a time.
The behavior, in this case, of the pipeline is the same if you are using the foreach command or if you are not. The data is not passed from the get-mailbox cmdlet down the pipeline until the cmdlet has gotten all of the needed data from AD (again a limitation of the cmdlet not of Powershell). I used the foreach cmdlet in my one line script only to break my get-mailbox command down into manageable / less resource intensive data sets not to improve the speed of command or change any behavior of Powershell.
Yes you are also correct that foreach is both an alias to the cmdlet foreach-object and a keyword recognized by Powershell (like the keyword “if”). The way to determine which one of these you are using is by their position in your statement. You will only use a keyword if the keyword comes at the beginning of the statement.
“Foreach ($value in $array) { <action> }” is going to use the keyword
“Get-childitem | foreach { <action> }” is going to be using the alias to the foreach-object cmdlet
Thank you for helping to clarify this for the readers of this blog by referencing people to your entry on the differences between the keyword and the cmdlet. I will continue to strive in my documentation to call the foreach command a command and the foreach keyword a keyword when each is appropriate.
I will shortly be making some modifications to this post that will correct the error in the second to last paragraph on the behavior of Powershell and that will further call out that I am using the foreach alias and not the keyword.
Thank you for your comments, please keep them coming.
Special thanks to Bruce Payette and his book for helping me understand what I was missing.
-Matthew