PowerShell parse eml file without unzip

Viewed 46

Currently I have a zip file containing some eml files, I need to parse and get all the emails in the From & To parts of each one of the eml files without unzipping the zip folder.

In order to read the eml files in my zip I'm using this code:

# Open outer ZIP as an archive
$zipFileContent = [IO.Compression.ZipFile]::OpenRead($file.FullName)
$emlEntries = $zipFileContent.Entries
$emlEntries | ForEach-Object {
     # Here I need to parse each eml file without unzipping them, to do so I'm trying this

     # Instantiate new ADODB Stream object
     $adoStream = New-Object -ComObject 'ADODB.Stream'    
     # Open stream
     $adoStream.Open()    
     # Load file
     $adoStream.LoadFromFile($_)    
     # Instantiate new CDO Message Object
     $cdoMessageObject = New-Object -ComObject 'CDO.Message'
     # Open object and pass stream
     $cdoMessageObject.DataSource.OpenObject($adoStream, '_Stream')
}
      

I'm getting an error, as the method LoadFromFile expects to have a "local" file instead of a System.IO.Compression.DeflateStream, could you please help me in order to achieve my goal please?

Thank you in advance.

0 Answers
Related