PowerTip: Use Windows PowerShell to Open Word Document

Doctor Scripto

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.

1 comment

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

  • abatha@o2.pl 0

    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

Feedback usabilla icon