Export to CSV and view screen output

Is there a way to export data as a CSV and view the output on the screen at the same time? The code below creates what I need, but if I use "tee" instead of Export-CSV, the data is saved as I see on the screen (as you 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" 

It 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 is as follows:

 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 so that they look like csv?

+4
source share
1 answer
 $foo | ConvertTo-Csv | Tee-Object -File output.csv | ConvertFrom-Csv 
+4
source

Source: https://habr.com/ru/post/1446318/


All Articles