I am having a little confusion about the various ways to print (echo) to the console. I have seen that there are multiple ways to write output to the console, such as:

Write-Host "Hello world1"
"Hello World2"
Out-Host -InputObject "Hello World3"

All three ways will print to the console. The middle one is somehow simpler and less verbose and easier to use. I also find that when you write a function such as:

function GetValues()
{
    "1"
    "2"
}

It still returns two strings in the pipeline:

And I'm still able to print out the values:

foreach ($s in GetValues)
{
    Write-Host "s: " $s
}

The thing that I have found was that using just the quoted string doesn't always appear on custom hosts, and that I have had to use Write-Host to get values to print on custom hosts.

Somehow I find this confusing. Is "Print something" supposed to be an alias to Write-Host or what is the intent?

Edit
Report