1

I am trying to get To, From, subject, sent date from about a 100 .msg files that are saved in a folder on my local drive, possibly get all that info in a csv using powershell.

I ran this code I got from another post

Get-ChildItem "C:\--------\msgfileshere" -Filter  *.msg |
ForEach-Object{
  $outlook = New-Object -comobject outlook.application
  $msg = $outlook.CreateItemFromTemplate($_.FullName)
  $msg | Select From,to,subject,Senton,Cc|ft -AutoSize
}

I am able to get Subject and Senton date.
But no other information comes out related to Sender, to, Cc. Am I missing something here?

Edit: I was able to get Sender info which gives System.__ComObject as the output but not the actual email address

User56756
  • 352
  • 4
  • 19
  • 1
    Your code does work for me, but only if the person exists in my contacts. You can use `$msg.sender | Select-Object -Property Address` to get the senders email address and `$msg.recipients | Select-Object -Property Address` to get all the recipient email address's. – Owain Esau Jun 24 '20 at 02:53
  • I'll give it a go and get back to you, thank you – User56756 Jun 24 '20 at 04:31
  • so I managed to get Sender which results in System.__ComObject instead of emailaddresss. – User56756 Jun 24 '20 at 06:35
  • 2
    As aside: do not keep creating a new outlook.application COM object and never release it from memory. You are bound to hit errors this way. Create the Outlook.application just once, before the loop and clean-up afterwards with `$null = [System.Runtime.Interopservices.Marshal]::ReleaseComObject($msg); $null = [System.Runtime.Interopservices.Marshal]::ReleaseComObject($outlook); [System.GC]::Collect(); [System.GC]::WaitForPendingFinalizers()` – Theo Jun 24 '20 at 12:05

0 Answers0