Has anyone else seen output display out of order in PowerShell 5?
C:\Users> Write-Host "Before"; Get-Service e* | select Status, Name, DisplayName; Write-Host "After"
Status Name DisplayName
------ ---- -----------
Stopped EapHost Extensible Authentication Protocol
Running EFS Encrypting File System (EFS)
Running eventlog Windows Event Log
Running EventSystem COM+ Event System
We noticed this after we upgraded to WMF5. It isn't causing any functional problems per se, but it can definitely confuse some people; scripts that uses Write-Host, Write-Verbose etc. to track the flow of the code could produce some surprising results.
Try Write-Output instead. Write-Host writes directly to the screen which could cause it to appear before a command that writes to the pipeline (Get-Service), even though it's technically entered after that command.