PowerShell Convert .msg to .pdf with attachments

Viewed 30

I have a large number of .msg files spread all around a shared drive that need converted to pdf. Adobe Acrobat can't open .msg so we're trying Powershell (vs 5) I've used the below script to do the conversion, but it leaves out attachments. I would really prefer to have embedded attachments over saving them as separate documents, which is what I've seen most people do. Any ideas?

$outlook = New-Object -ComObject Outlook.Application
$word = New-Object -ComObject Word.Application

Get-ChildItem -Path $folderPath -Filter *.msg? | ForEach-Object {

    $msgFullName = $_.FullName
   $docFullName = $msgFullName -replace '\.msg$', '.doc'
    $pdfFullName = $msgFullName -replace '\.msg$', '.pdf'

    $msg = $outlook.CreateItemFromTemplate($msgFullName)
    $msg.SaveAs($docFullName, 4)

    $doc = $word.Documents.Open($docFullName)
    $doc.SaveAs([ref] $pdfFullName, [ref] 17)

    $doc.Close()
 }
0 Answers
Related