Question:
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:
1 2 3 |
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:
1 2 3 4 |
#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:
1 2 3 4 5 6 |
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?
Answer:
1 2 |
$foo | ConvertTo-Csv | Tee-Object -File output.csv | ConvertFrom-Csv |