Hi all,
I'm working on a script that automates account creation and notification for our students. I've completed a significant chunk of the script and have it successfully creating AD accounts and e-mailing students their credentials to access our system from a batch job that runs nightly. I want to add an additional part that will create a document using a Microsoft word template that is associated with a CSV file that the script will be populating each day it runs. The goal is to create a mail merged PDF that I can give to our admissions folks that has all the pertinent information for students to login. They will put these documents in their admissions packets or hand them to new students so they can login to the student system. I think I'm almost there as I can get word to create a PDF of the template. The only problem is I have no idea how to get it to execute the mail merge so that the pdf contains the actual data I need it to. Currently all I end up with is an export of the template itself in PDF format.
I'm sure the problem with this is that I'm having trouble calling the .net functions for Word via powershell. Online I see various documents on how to do this with vb.net however Powershell instructions seem to not exist. I'm sure the actions are quite similar but I need some help. Here is the section of the code I have currently:
$filename = "EmailTemplate1.dotx" $filename2 = "EmailTemplateProc.pdf" $word=new-object -com Word.Application $doc=$word.Documents.Add($filename) $word.Visible=$False $word.ActiveDocument.Fields.Update() $doc.WdMailMergeDestination.wdSendToNewDocument $word.ActiveDocument $Doc.saveas([ref] $filename2, [ref] 17) $Doc.close() $word.Quit()
I'm sure the problem lies somewhere at the $doc.WdMailMergeDestination and onward. Basically I want it to take the dotx file which already has the templated document with mail merged fields and save an executed mail merge as a PDF. Any insight would be great.
Thanks in advance!