pipe output to the screen as well as to 'append' it to a variable.

I would like to be able to pipe output to the screen as well as to ‘append’ it to a variable.

For example, for something like this:

$result =@()
$result += Invoke-Command -cn $servers -scriptblock { foo }

I would like to be able to see on the screen the running output of

Invoke-Command -cn $servers -scriptblock { foo }

as well as capture each result to the $result variable.

Try using the tee-object look here: https://technet.microsoft.com/en-us/library/hh849937.aspx