I have a function which prints the result of an Exchange cmdlet. But the output is not printed immediately. It is almost like it kind of runs asynchronous.
In the following example the output is printed AFTER the first Read-Host
break. I expected it would print immediately, that is before the first Read-Host
break.
I also tried to experience with Start-Sleep -S 1
but it didn't change anything.
Apparently there is something basic understanding I don't have. Can someone point me in the right direction?
Function GetMailboxFolders {
$MBID = 15
Get-MailboxFolderStatistics -Identity ((Get-Mailbox)[$MBID].alias) |
Select-Object Identity, ItemsInFolder, FolderSize
Read-Host -Prompt 'Push key to continue(1)'
# The result of the cmdlet is printed here!?
Read-Host -Prompt 'Push key to continue(2)'
}
If I don't add the | Select-Object ...
it prints immediately/run synchronously...why?