September 14th, 2014

PowerTip: Use Windows PowerShell to Open Word Document

Doctor Scripto
Scripter

Summary: Learn how to use Windows PowerShell to open a Microsoft Word document.

Hey, Scripting Guy! Question How can I open a Word document with Windows PowerShell?

Hey, Scripting Guy! Answer 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.

Author

The "Scripting Guys" is a historical title passed from scripter to scripter. The current revision has morphed into our good friend Doctor Scripto who has been with us since the very beginning.

1 comment

Discussion is closed. Login to edit/delete existing comments.

  • abatha@o2.pl

    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