1

This is my very first StackOverflow post so I will try to be undestandable as much as possible :D

I'm parsing some .pst files to get all the mails and their properties and then export them as .csv files.
The thing is I don't want the attachments as a list or string. I want to create a new column in the CSV for each of them.

Let's say this are my datas :

Sender       : bla@bla.com
Receiver     : blu@blu.com
Subject      : How not to die
Attachments  : BestCatPic.jpg BestDogPic.jpg

Then I add each attachments as new properties ($piece is a number):
$email | Add-Member -NotePropertyName "Attachment-$piece" -NotePropertyValue "$e"

And this is working because then my datas looks like this :

Sender       : bla@bla.com
Receiver     : blu@blu.com
Subject      : How not to die
Attachments  : BestCatPic.jpg BestDogPic.jpg
Attachment-1 : BestCatPic.jpg 
Attachment-2 : BestDogPic.jpg

My problem is that when I use Export-Csv, the datas are the same as if I didn't used add-member and the new properties like Attachment-1 does not appears in my CSV file.

Here is my Export-Csv line ($email_out is my list of all mails):
$email_out | Export-Csv -Encoding UTF8 $pstName -NoTypeInformation

Do you guys have any idea why or what could help ?

Bruuuh
  • 123
  • 11
  • 2
    When you export to csv the columns are created from the first item. You cannot add columns after this. Either create ALL the fields you need to start with using a "dummy" entry or compile a PSobject holding all the data and then send to csv when complete. – Scepticalist Nov 26 '19 at 11:47
  • That makes sense, thanks a lot ! – Bruuuh Nov 26 '19 at 12:25
  • Possible duplicate of [Not all properties displayed](https://stackoverflow.com/questions/44428189/not-all-properties-displayed) – iRon Nov 26 '19 at 15:57
  • 1
    Or use the function [here](https://stackoverflow.com/a/58915598/9898643) – Theo Nov 26 '19 at 19:23
  • I already added them manually but this looks like a good way too ! Thanks – Bruuuh Nov 27 '19 at 08:42

0 Answers0