PowerShell Tee to console in a pipeline

Viewed 58

I generate a csv file :

myscript.ps1 | Export-Csv result.csv

but it's a slow process and I'd like to see progress. I thought Tee-Object would do it but I'm looking for a 'Tee to console' effect which Tee-Object doesn't seem to offer?

If I do

myscript.ps1 | Write-Host | Export-Csv result.csv

that destroys the objects. How can I Tee-Host ?

2 Answers

Use ForEach-Object:

myscript.ps1 |ForEach-Object { $_ |Out-Host; $_ } |Export-Csv ...

Mathias has answered exactly what you asked, but as an alternative I'd suggest using write-progress as a way of getting a visual indication of how a task is progressing.

Related