I have created a newsletter in a word office with the .docx extension. I want to read the file and copy the content to a body of an email and send it across a large audience inside the organization.
$filepath="D:\WORK\JULY-2019\NewLetter\PerformanceNewsLetter.docx"
$word = New-Object -ComObject Word.Application
$doc = $word.Documents.Open($filepath)
$body = $doc.Content.Select()
$doc.Close()
$word.Quit()
$recipients = "jmallick@gmail.com,panan@gmail.com"
[string[]]$To = $recipients.Split(',')
Send-MailMessage -SmtpServer mail.test.net -To $To -From "jmallick@gmail" -Subject "NewLetter For the month July 2019" -Body $body -BodyAsHtml
While running the code I am getting the following error
New-Object : Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 800700c1 is not a valid Win32 application. (Exception from HRESULT: 0x800700C1).
At D:\NewLetterTemplate.ps1:17 char:9
+ $word = New-Object -ComObject Word.Application
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-Object], BadImageFormatException
+ FullyQualifiedErrorId : System.BadImageFormatException,Microsoft.PowerShell.Commands.NewObjectCommand
I have checked the code on visual studio code as well on Powershell-ise and getting the same error on both.
I check my windows version is 7 and 64bit and the powershell version it the major 5 and it is also 64bit.
User contributions licensed under CC BY-SA 3.0