Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Export to CSV and view output on the screen

Tags:

powershell

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?

like image 607
User_1403834 Avatar asked Nov 15 '12 19:11

User_1403834


Video Answer


1 Answers

$foo | ConvertTo-Csv | Tee-Object -File output.csv | ConvertFrom-Csv
like image 192
Ansgar Wiechers Avatar answered Oct 30 '22 21:10

Ansgar Wiechers