I've been working on this script for work and ran into something weird. My script is available here and I've focused near the problem line.

When I run this script it will output "Returned services:", then outputs the text for the Get-Index function, and after receiving the input will output the content of $Services to the console. I need it to output the content of $Services so the user knows which service to select in Get-Index.

Please attach your script to your post. The "Full Editor" has a place to attach scripts.

When using Write-Host to output lines to the console the output is independent of the pipeline and, most of the time, will come out before pipeline output. See the main PowerShell documentation for more information on output in PowerShell.

I believe I get what you mean with Write-Host. If I swap out Write-Output with Write-Host, it does go to the console in the correct order.

The problem at this point is the output that Write-Host sends, isn't formatted the way Write-Output is, so I'm wondering if there's a way to get Write-Output to send this output to the console so I don't have to manually format the content.

Your code is quite odd. I recommend not using a bunch of one time functions and build this as a simple script that uses more standard coding for WMF 3 and later. This will help simplify your code. Also when trying to debug issues that you do not understand start by throwing out all code that is decoration and concentrate on the basic minimal needs of the task.

Here is an example of how to clean up the code so that it is easier to debug. Also use a PS1 file until you resolve all coding issues then move it to a module.

[System.Management.Automation.PSObject]
$Services,[/b}
$services can be an array. If you don't declare it as an array funny things will happen.

The normal method would be:[object[]]$services

or

[array]$services

or

[psobject[]]$services

The better design practice would put index generation and screen menu code in one place and not scattered all over. Just get all services and keep the complete object. Use the services ID to identify the service.

Ok - now that I have fixed PSS, there is another issue that is common with design of scripts. The use or "Read-Host" in the pipeline will also cause all output to cease until the CmdLet is answered. This is a drawback to using Read-Hot in a pipeline.

In modules and scripts files you either need to arrange to use console output to prompt or you need to not use Read-Host. This is where Write-Host gets you out of the box.