2

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 ?

Chris F Carroll
  • 11,146
  • 3
  • 53
  • 61

2 Answers2

3

Use ForEach-Object:

myscript.ps1 |ForEach-Object { $_ |Out-Host; $_ } |Export-Csv ...
Mathias R. Jessen
  • 157,619
  • 12
  • 148
  • 206
  • 2
    This is tempting, but applying `Out-Host` to _individual_ objects will result in unexpected table formatting, as each object will be in its own table, with its own header. Try `$result = Get-ChildItem / | % { $_ | Out-Host; $_ }` To solve that problem, a proxy function is needed. However, in PowerShell (Core) 7+ you can simply pipe to `Tee-Object ($IsWindows ? 'CON' : '/dev/tty')` – mklement0 Aug 19 '22 at 14:05
2

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.

Tom
  • 880
  • 6
  • 17