Using PowerShell to update variables within a Word document...

I have created a PowerShell script to create a user in Active Directory, create their home folder and assign their permissions, assign their Office 365 licensing and email various individuals with our organization to tell those individuals they need to do their part to welcome the newcomer.  I have also created a Word document that I would like to update and then send on to HR with this individual's specifics to so they would have this to hand to the newcomer on their first day, HOWEVER, I can not figure out how to accomplish this last piece.

I can open the document in PowerShell and I can manipulate the variables in VBA but I can't figure out how to change the variable from within PowerShell.  So, for example, the PowerShell script has a variable $username.  The Word document has a textbox named username.  When I try:

$range.username.text = "$username"

I get an error that tells me:

Property 'Text' cannot be found on this object; make sure it exists and is settable.

I'm sure it is either a formatting error on my part or how I am calling the variables but I have been unsuccessful in finding a good lead in how to resolve this.

Any assistance would be greatly appreciated!

August 24th, 2015 12:42pm

Hi,

This is the forum to discuss questions and feedback for Microsoft Word, the issue is more related to Word coding/programing, you'd better post your question to the MSDN forum for Word

http://social.msdn.microsoft.com/Forums/en-US/home?forum=worddev&filter=alltypes&sort=lastpostdesc

The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.

George Zhao
TechNet Community Support

Free Windows Admin Tool Kit Click here and download it now
August 24th, 2015 9:28pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics