Summary: Learn how to use Windows PowerShell to open a Microsoft Word document.
How can I open a Word document with Windows PowerShell?
Use the New-Object cmdlet:
$Filename='C:\HappyBirthdayEd.docx'
$Word=NEW-Object –comobject Word.Application
$Document=$Word.documents.open($Filename)
You can now programmatically access methods and properties to edit the Word document.
Hey, this is rather an old post. I hope someone is still looking at this blog :)I have PowerShell version 5.1 and this method no longer works. The error that I’m getting is: “You cannot call a method on a null-valued expression”, indicating that the $Word.documents list is null (which is true).
Do you have any idea how to crack it?
Thanks for any help