7

Is there a way to export data as a CSV and view the output on the screen at the same time? The code below produces what I need, but if I use "tee" instead of Export-CSV, the data is stored the same way as I see on the screen (as I would expect)

Code:

Get-ChildItem  \\server\share-recurse -Filter "*.pst" | Where {$_.Length -gt 0} | 
Select-Object Directory, Name, Length, CreationTime, LastWriteTime | Export-Csv "C:\CSVs\mynew.csv"

Produces:

#TYPE Selected.System.IO.FileInfo
"Directory","Name","Length","CreationTime","LastAccessTime","LastWriteTime"
\\server\share\nightly.188\share\name","name.pst","271360","6/4/2009 2:42:21 PM","8/2/2011 12:00:32 AM","6/9/2011 8:58:50 AM"

If I use "tee", the Output on the screen and in the file look like this:

Directory     : \\server\share\nightly.188\share\name
Name          : name.pst
Length        : 271360
CreationTime  : 6/4/2009 2:42:21 PM
LastWriteTime : 6/9/2011 8:58:50 AM

Is there a way to format the screen and csv to look like a csv?

1
  • 1
    First, format for the screen. Then output to CSV. Two different commands. What's the problem? Nov 15, 2012 at 19:56

1 Answer 1

10
$foo | ConvertTo-Csv | Tee-Object -File output.csv | ConvertFrom-Csv
3
  • This gave me the outputs that I needed. Thank you! Nov 16, 2012 at 16:51
  • This seemed to create for me a CSV that Excel opens everything in 1 column. No idea why. Sep 21, 2018 at 12:49
  • @Nullldata Because your system locale doesn't specify , as the default field separator. Sep 21, 2018 at 14:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.